【问题标题】:Terraform Bigquery Table Schema in a separate JSON file单独 JSON 文件中的 Terraform Bigquery 表架构
【发布时间】:2022-01-22 06:19:01
【问题描述】:

我知道我们可以在 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 导入。

【问题讨论】:

    标签: google-bigquery terraform


    【解决方案1】:

    如果架构不会动态生成,那么您可以为此使用file function:

    schema = file("${path.module}/nested_path_to/schema.json")
    

    schema.json:

    [
      {
        "name": "permalink",
        "type": "STRING",
        "mode": "NULLABLE",
        "description": "The Permalink"
      }
    ]
    

    如果架构是动态生成的,那么您应该为此使用templatefile function:

    schema = templatefile("${path.module}/nested_path_to/schema.json.tmpl", { variable_name = variable_value } )
    

    【讨论】:

    • 非常感谢马特
    猜你喜欢
    • 2017-01-03
    • 2020-03-22
    • 1970-01-01
    • 2019-05-31
    • 2020-10-03
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2021-10-05
    相关资源
    最近更新 更多