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 #10179

Merged
merged 8 commits into from
Mar 12, 2024
Merged
1 change: 1 addition & 0 deletions mmv1/products/notebooks/Instance.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ properties:
The Compute Engine tags to add to instance.
item_type: Api::Type::String
default_from_api: true
diff_suppress_func: NotebooksInstanceTagsDiffSuppress
- !ruby/object:Api::Type::KeyValuePairs
name: 'metadata'
description: |
Expand Down
18 changes: 16 additions & 2 deletions mmv1/templates/terraform/constants/notebooks_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,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 @@ -17,7 +31,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
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ resource "google_notebooks_instance" "<%= ctx[:primary_resource_id] %>" {
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/userinfo.email"
]

tags = ["foo", "bar"]

disk_encryption = "CMEK"
kms_key = "<%= ctx[:vars]['key_name'] %>"
desired_state = "ACTIVE"
Expand Down