Skip to content

Commit fe8df03

Browse files
fix tags cause notebooks instances to recreate (#10179) (#17559)
* 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 <[email protected]>
1 parent a2223bb commit fe8df03

File tree

4 files changed

+31
-7
lines changed

4 files changed

+31
-7
lines changed

.changelog/10179.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
notebooks: fixed an issue where default tags would cause a diff recreating `google_notebooks_instance` resources
3+
```

google/services/notebooks/resource_notebooks_instance.go

+22-7
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,22 @@ var NotebooksInstanceProvidedScopes = []string{
4040
"https://www.googleapis.com/auth/userinfo.email",
4141
}
4242

43+
var NotebooksInstanceProvidedTags = []string{
44+
"deeplearning-vm",
45+
"notebook-instance",
46+
}
47+
4348
func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData) bool {
44-
old, new := d.GetChange("service_account_scopes")
49+
return NotebooksDiffSuppressTemplate("service_account_scopes", NotebooksInstanceProvidedScopes, d)
50+
}
51+
52+
func NotebooksInstanceTagsDiffSuppress(_, _, _ string, d *schema.ResourceData) bool {
53+
return NotebooksDiffSuppressTemplate("tags", NotebooksInstanceProvidedTags, d)
54+
}
55+
56+
func NotebooksDiffSuppressTemplate(field string, defaults []string, d *schema.ResourceData) bool {
57+
old, new := d.GetChange(field)
58+
4559
oldValue := old.([]interface{})
4660
newValue := new.([]interface{})
4761
oldValueList := []string{}
@@ -54,7 +68,7 @@ func NotebooksInstanceScopesDiffSuppress(_, _, _ string, d *schema.ResourceData)
5468
for _, item := range newValue {
5569
newValueList = append(newValueList, item.(string))
5670
}
57-
newValueList = append(newValueList, NotebooksInstanceProvidedScopes...)
71+
newValueList = append(newValueList, defaults...)
5872

5973
sort.Strings(oldValueList)
6074
sort.Strings(newValueList)
@@ -469,11 +483,12 @@ Enabled by default.`,
469483
Format: projects/{project_id}/regions/{region}/subnetworks/{subnetwork_id}`,
470484
},
471485
"tags": {
472-
Type: schema.TypeList,
473-
Computed: true,
474-
Optional: true,
475-
ForceNew: true,
476-
Description: `The Compute Engine tags to add to instance.`,
486+
Type: schema.TypeList,
487+
Computed: true,
488+
Optional: true,
489+
ForceNew: true,
490+
DiffSuppressFunc: NotebooksInstanceTagsDiffSuppress,
491+
Description: `The Compute Engine tags to add to instance.`,
477492
Elem: &schema.Schema{
478493
Type: schema.TypeString,
479494
},

google/services/notebooks/resource_notebooks_instance_generated_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ resource "google_notebooks_instance" "instance" {
263263
"https://www.googleapis.com/auth/cloud-platform",
264264
"https://www.googleapis.com/auth/userinfo.email"
265265
]
266+
267+
tags = ["foo", "bar"]
268+
266269
disk_encryption = "CMEK"
267270
kms_key = "%{key_name}"
268271
desired_state = "ACTIVE"

website/docs/r/notebooks_instance.html.markdown

+3
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ resource "google_notebooks_instance" "instance" {
161161
"https://www.googleapis.com/auth/cloud-platform",
162162
"https://www.googleapis.com/auth/userinfo.email"
163163
]
164+
165+
tags = ["foo", "bar"]
166+
164167
disk_encryption = "CMEK"
165168
kms_key = "my-crypto-key"
166169
desired_state = "ACTIVE"

0 commit comments

Comments
 (0)