I am trying to deploy BigQuery scheduled query using terraform but I do not know how I can use list and for_each syntax.
I have this template file.
SELECT *
FROM mydataset.mytable_${suffix}
Then generate a list of query using template_file module. var.suffix_list here is a list of string.
data "template_file" "query" {
for_each = var.suffix_list # list(string)
template = "file/path/to/template/file"
vars = {
suffix = each.value
}
}
From this module I want to generate a list of query.
output "query" {
value = # a list of rendered query
}
This output will be an input of google_bigquery_data_transfer_config resource.
resource "google_bigquery_data_transfer_config" "query_config" {
for_each = # a list of rendered query
data_refresh_window_days = var.data_refresh_window_days
data_source_id = "scheduled_query"
display_name = var.display_name
disabled = var.disabled
destination_dataset_id = var.destination_dataset_id
location = var.query_location
project = var.gcp_project
schedule = var.query_schedule
params = {
destination_table_name_template = var.destination_table_name_template
query = each.value
}
}
How can I output definition and an input for google_bigquery_data_transfer_config?
Thanks in advance.