I know we can define table schemas in Terraform files. My question is, Is there a way to define schemas in separate files and Terraform import it at run time. That way it will be offer better management and readability
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
}
So basically what I am asking is how can I move the schema portion to separate files and at run time TF imports that.
If the schema will not be dynamically generated, then you can use the file
function for this purpose:
schema = file("${path.module}/nested_path_to/schema.json")
schema.json:
[
{
"name": "permalink",
"type": "STRING",
"mode": "NULLABLE",
"description": "The Permalink"
}
]
If the schema will be dynamically generated, then you should use the templatefile
function for this purpose:
schema = templatefile("${path.module}/nested_path_to/schema.json.tmpl", { variable_name = variable_value } )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With