我知道我们可以在 Terraform 文件中定义表架构。我的问题是,有没有一种方法可以在单独的文件中定义模式,然后 Terraform 在运行时将其导入。这样它将提供更好的管理和可读性
resource "google_bigquery_table" "default" {
dataset_id = google_bigquery_dataset.default.dataset_id
table_id = "bar"
time_partitioning {
type = "DAY"
}
labels = {
env = "default"
}
**schema = <<EOF
[
{
"name": "permalink",
"type": "STRING",
"mode": "NULLABLE",
"description": "The Permalink"
}
]**
EOF
}
所以基本上我要问的是如何将模式部分移动到单独的文件并在运行时 TF 导入它。
最佳答案
如果模式不会动态生成,那么您可以使用文件
function为此目的:
schema = file("${path.module}/nested_path_to/schema.json")
架构.json:
[
{
"name": "permalink",
"type": "STRING",
"mode": "NULLABLE",
"description": "The Permalink"
}
]
如果模式将动态生成,那么您应该使用模板文件
function为此目的:
schema = templatefile("${path.module}/nested_path_to/schema.json.tmpl", { variable_name = variable_value } )
关于google-bigquery - 单独的 JSON 文件中的 Terraform Bigquery 表架构,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70425085/