From a6d991f1d97e6640a57429450fc0d56b6d3c69c5 Mon Sep 17 00:00:00 2001 From: Modular Magician Date: Tue, 12 Mar 2024 22:24:49 +0000 Subject: [PATCH] fix tags cause notebooks instances to recreate (#10179) * add labels to runtime update test * Add labels to ImportStateVerifyIgnore * fix indentation * fix tags cause notebooks instances to create [upstream:aba1d05f1ea4bd7e93a485044fa19870bd887ddd] Signed-off-by: Modular Magician --- .changelog/10179.txt | 3 ++ .../notebooks/resource_notebooks_instance.go | 29 ++++++++++++++----- ...ource_notebooks_instance_generated_test.go | 3 ++ .../docs/r/notebooks_instance.html.markdown | 3 ++ 4 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 .changelog/10179.txt diff --git a/.changelog/10179.txt b/.changelog/10179.txt new file mode 100644 index 00000000000..6c32bfe67df --- /dev/null +++ b/.changelog/10179.txt @@ -0,0 +1,3 @@ +```release-note:bug +notebooks: fixed an issue where default tags would cause a diff recreating `google_notebooks_instance` resources +``` \ No newline at end of file diff --git a/google/services/notebooks/resource_notebooks_instance.go b/google/services/notebooks/resource_notebooks_instance.go index 722fc83b368..0a1af96df97 100644 --- a/google/services/notebooks/resource_notebooks_instance.go +++ b/google/services/notebooks/resource_notebooks_instance.go @@ -40,8 +40,22 @@ var NotebooksInstanceProvidedScopes = []string{ "https://www.googleapis.com/auth/userinfo.email", } +var NotebooksInstanceProvidedTags = []string{ + "deeplearning-vm", + "notebook-instance", +} + func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { - old, new := d.GetChange("service_account_scopes") + return NotebooksDiffSuppressTemplate("service_account_scopes", NotebooksInstanceProvidedScopes, d) +} + +func NotebooksInstanceTagsDiffSuppress(_, _, _ string, d *schema.ResourceData) bool { + return NotebooksDiffSuppressTemplate("tags", NotebooksInstanceProvidedTags, d) +} + +func NotebooksDiffSuppressTemplate(field string, defaults []string, d *schema.ResourceData) bool { + old, new := d.GetChange(field) + oldValue := old.([]interface{}) newValue := new.([]interface{}) oldValueList := []string{} @@ -54,7 +68,7 @@ func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) for _, item := range newValue { newValueList = append(newValueList, item.(string)) } - newValueList = append(newValueList, NotebooksInstanceProvidedScopes...) + newValueList = append(newValueList, defaults...) sort.Strings(oldValueList) sort.Strings(newValueList) @@ -469,11 +483,12 @@ Enabled by default.`, Format: projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`, }, "tags": { - Type: schema.TypeList, - Computed: true, - Optional: true, - ForceNew: true, - Description: `The Compute Engine tags to add to instance.`, + Type: schema.TypeList, + Computed: true, + Optional: true, + ForceNew: true, + DiffSuppressFunc: NotebooksInstanceTagsDiffSuppress, + Description: `The Compute Engine tags to add to instance.`, Elem: &schema.Schema{ Type: schema.TypeString, }, diff --git a/google/services/notebooks/resource_notebooks_instance_generated_test.go b/google/services/notebooks/resource_notebooks_instance_generated_test.go index 09b39055a20..c5efeb2ac76 100644 --- a/google/services/notebooks/resource_notebooks_instance_generated_test.go +++ b/google/services/notebooks/resource_notebooks_instance_generated_test.go @@ -263,6 +263,9 @@ resource "google_notebooks_instance" "instance" { "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/userinfo.email" ] + + tags = ["foo", "bar"] + disk_encryption = "CMEK" kms_key = "%{key_name}" desired_state = "ACTIVE" diff --git a/website/docs/r/notebooks_instance.html.markdown b/website/docs/r/notebooks_instance.html.markdown index 18066af238c..66814146d7c 100644 --- a/website/docs/r/notebooks_instance.html.markdown +++ b/website/docs/r/notebooks_instance.html.markdown @@ -161,6 +161,9 @@ resource "google_notebooks_instance" "instance" { "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/userinfo.email" ] + + tags = ["foo", "bar"] + disk_encryption = "CMEK" kms_key = "my-crypto-key" desired_state = "ACTIVE"