From fa120b7985329c27d29d7732b8e36a85d49c4324 Mon Sep 17 00:00:00 2001 From: Cas Date: Wed, 11 Dec 2024 13:53:26 +0100 Subject: [PATCH] Trying workaround for labeling scheduled queries (#105) * trying workaround for labeling scheduled queries * path fix? * path fix? * tweaked formatting * proper support for multiple labels * removed need for separate template * fixed bad concat --- terraform/bigquery_scheduled_data_transfer/main.tf | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/terraform/bigquery_scheduled_data_transfer/main.tf b/terraform/bigquery_scheduled_data_transfer/main.tf index dddcb9a..18f2acf 100644 --- a/terraform/bigquery_scheduled_data_transfer/main.tf +++ b/terraform/bigquery_scheduled_data_transfer/main.tf @@ -23,12 +23,15 @@ resource "google_bigquery_data_transfer_config" "default" { destination_dataset_id = var.destination_dataset_id params = { - query = templatefile( - var.query_template, - merge(var.query_variables, { interval = try(local.bigquery_interval_mappings[var.interval], var.interval) }) - ) destination_table_name_template = var.destination_table_name_template - write_disposition = var.write_disposition + query = join("", [ + length(var.labels) > 0 ? format("SET @@query_label = \"%s\";\n\n", join(",", [for key, value in var.labels : format("%s:%s", key, value)])) : "", + templatefile( + var.query_template, + merge(var.query_variables, { interval = try(local.bigquery_interval_mappings[var.interval], var.interval) }) + ) + ]) + write_disposition = var.write_disposition } # formatting rules are quite hard to generalize, see: https://cloud.google.com/appengine/docs/flexible/scheduling-jobs-with-cron-yaml#cron_yaml_The_schedule_format