From 799f1e0ca9662acfa5614c191f9dfd6ea3283d7e Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Wed, 27 Oct 2021 15:39:57 +0000 Subject: [PATCH] make ForceNew on newly added required field (#5362) * make ForceNew on newly added required field * Update resource_bigquery_table.go Fixed a typo Signed-off-by: Modular Magician --- .changelog/5362.txt | 3 +++ google/resource_bigquery_table.go | 11 +++++++++++ google/resource_container_node_pool.go | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 .changelog/5362.txt diff --git a/.changelog/5362.txt b/.changelog/5362.txt new file mode 100644 index 00000000000..2d71057ec4b --- /dev/null +++ b/.changelog/5362.txt @@ -0,0 +1,3 @@ +```release-note:bug +bigquery: fixed a bug of cannot add required fields to an existing schema on `google_bigquery_table` +``` diff --git a/google/resource_bigquery_table.go b/google/resource_bigquery_table.go index 4a8bd4e6625..1b7acd7f8cd 100644 --- a/google/resource_bigquery_table.go +++ b/google/resource_bigquery_table.go @@ -225,6 +225,17 @@ func resourceBigQueryTableSchemaIsChangeable(old, new interface{}) (bool, error) return false, err } mapNew := bigQueryArrayToMapIndexedByName(arrayNew) + for key := range mapNew { + // making unchangeable if an newly added column is with REQUIRED mode + if _, ok := mapOld[key]; !ok { + items := mapNew[key].(map[string]interface{}) + for k := range items { + if k == "mode" && fmt.Sprintf("%v", items[k]) == "REQUIRED" { + return false, nil + } + } + } + } for key := range mapOld { // all old keys should be represented in the new config if _, ok := mapNew[key]; !ok { diff --git a/google/resource_container_node_pool.go b/google/resource_container_node_pool.go index 6cf6977b68e..6811a4099f3 100644 --- a/google/resource_container_node_pool.go +++ b/google/resource_container_node_pool.go @@ -1,13 +1,13 @@ package google import ( - "context" "fmt" "log" "regexp" "strings" "time" + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/customdiff" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"