From 7c6211a494f46e5bb3f9a8595c7a03483dfc4363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Taneli=20Lepp=C3=A4?= Date: Thu, 16 Oct 2025 15:12:23 +0200 Subject: [PATCH] bigquery-dataset: fix issues (#3425) * bigquery-dataset: add missing return_type to routines, fix view schema encode, add dependency between routines and views * Fix test. --------- Co-authored-by: Julio Castillo --- modules/bigquery-dataset/README.md | 8 ++++---- modules/bigquery-dataset/main.tf | 5 +++-- modules/bigquery-dataset/variables.tf | 1 + tests/modules/bigquery_dataset/examples/routines.yaml | 4 ++-- 4 files changed, 10 insertions(+), 8 deletions(-) diff --git a/modules/bigquery-dataset/README.md b/modules/bigquery-dataset/README.md index 5e4cb780a..44f25427c 100644 --- a/modules/bigquery-dataset/README.md +++ b/modules/bigquery-dataset/README.md @@ -370,10 +370,10 @@ module "bigquery-dataset" { | [location](variables.tf#L122) | Dataset location. | string | | "EU" | | [materialized_views](variables.tf#L128) | Materialized views definitions. | map(object({…})) | | {} | | [options](variables.tf#L161) | Dataset options. | object({…}) | | {} | -| [routines](variables.tf#L180) | Routine definitions. | map(object({…})) | | {} | -| [tables](variables.tf#L218) | Table definitions. Options and partitioning default to null. Partitioning can only use `range` or `time`, set the unused one to null. | map(object({…})) | | {} | -| [tag_bindings](variables.tf#L303) | Tag bindings for this dataset, in key => tag value id format. | map(string) | | {} | -| [views](variables.tf#L310) | View definitions. | map(object({…})) | | {} | +| [routines](variables.tf#L180) | Routine definitions. | map(object({…})) | | {} | +| [tables](variables.tf#L219) | Table definitions. Options and partitioning default to null. Partitioning can only use `range` or `time`, set the unused one to null. | map(object({…})) | | {} | +| [tag_bindings](variables.tf#L304) | Tag bindings for this dataset, in key => tag value id format. | map(string) | | {} | +| [views](variables.tf#L311) | View definitions. | map(object({…})) | | {} | ## Outputs diff --git a/modules/bigquery-dataset/main.tf b/modules/bigquery-dataset/main.tf index 2ed2f9927..17b676848 100644 --- a/modules/bigquery-dataset/main.tf +++ b/modules/bigquery-dataset/main.tf @@ -373,7 +373,7 @@ resource "google_bigquery_table" "default" { } resource "google_bigquery_table" "views" { - depends_on = [google_bigquery_table.default] + depends_on = [google_bigquery_table.default, google_bigquery_routine.default] for_each = var.views project = local.project_id dataset_id = google_bigquery_dataset.default.dataset_id @@ -382,7 +382,7 @@ resource "google_bigquery_table" "views" { description = each.value.description labels = each.value.labels deletion_protection = each.value.deletion_protection - schema = try(jsonencode(each.value.schema), null) + schema = each.value.schema != null ? jsonencode(each.value.schema) : null view { query = each.value.query @@ -445,6 +445,7 @@ resource "google_bigquery_routine" "default" { imported_libraries = each.value.imported_libraries determinism_level = each.value.determinism_level data_governance_type = each.value.data_governance_type + return_type = each.value.return_type return_table_type = each.value.return_table_type dynamic "arguments" { for_each = each.value.arguments diff --git a/modules/bigquery-dataset/variables.tf b/modules/bigquery-dataset/variables.tf index ff6394cb0..9e797b3f4 100644 --- a/modules/bigquery-dataset/variables.tf +++ b/modules/bigquery-dataset/variables.tf @@ -187,6 +187,7 @@ variable "routines" { imported_libraries = optional(list(string)) determinism_level = optional(string) data_governance_type = optional(string) + return_type = optional(string) return_table_type = optional(string) arguments = optional(map(object({ argument_kind = optional(string) diff --git a/tests/modules/bigquery_dataset/examples/routines.yaml b/tests/modules/bigquery_dataset/examples/routines.yaml index 03ae72cce..dfc1d8b52 100644 --- a/tests/modules/bigquery_dataset/examples/routines.yaml +++ b/tests/modules/bigquery_dataset/examples/routines.yaml @@ -48,7 +48,7 @@ values: project: my-project remote_function_options: [] return_table_type: null - return_type: null + return_type: '{"typeKind":"STRING"}' routine_id: custom_masking_routine routine_type: SCALAR_FUNCTION spark_options: [] @@ -58,4 +58,4 @@ counts: google_bigquery_dataset: 1 google_bigquery_routine: 1 modules: 1 - resources: 2 \ No newline at end of file + resources: 2