Skip to content

Commit

Permalink
fix tags cause notebooks instances to recreate (#10179) (#17559)
Browse files Browse the repository at this point in the history
* 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 <magic-modules@google.com>
  • Loading branch information
modular-magician committed Mar 12, 2024
1 parent a2223bb commit fe8df03
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .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
```
29 changes: 22 additions & 7 deletions google/services/notebooks/resource_notebooks_instance.go
Expand Up @@ -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{}
Expand All @@ -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)
Expand Down Expand Up @@ -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,
},
Expand Down
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions website/docs/r/notebooks_instance.html.markdown
Expand Up @@ -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"
Expand Down

0 comments on commit fe8df03

Please sign in to comment.