Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Terraform Bigquery Table Schema in a separate JSON file

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.

like image 344
InTheWorldOfCodingApplications Avatar asked Oct 16 '25 11:10

InTheWorldOfCodingApplications


1 Answers

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 } )
like image 51
Matt Schuchard Avatar answered Oct 18 '25 08:10

Matt Schuchard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!