Skip to content

Commit

Permalink
fix tags cause notebooks instances to recreate (GoogleCloudPlatform#1…
Browse files Browse the repository at this point in the history
…0179)

* add labels to runtime update test

* Add labels to ImportStateVerifyIgnore

* fix indentation

* fix tags cause notebooks instances to create
  • Loading branch information
bcreddy-gcp authored and balanaguharsha committed May 2, 2024
1 parent e305199 commit 358c29e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 2 deletions.
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

0 comments on commit 358c29e

Please sign in to comment.