Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix tags cause notebooks instances to recreate #17559

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/10179.txt
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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