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"