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

Check set equality for service account scope changes #1130

Merged
merged 5 commits into from
Feb 27, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 18 additions & 2 deletions google/resource_compute_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1252,8 +1252,24 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
d.SetPartial("attached_disk")
}

// d.HasChange("service_account") is oversensitive: see https://github.com/hashicorp/terraform/issues/17411
// Until that's fixed, manually check whether there is a change.
o, n := d.GetChange("service_account")
oList := o.([]interface{})
nList := n.([]interface{})
scopesChange := false
if len(oList) != len(nList) {
scopesChange = true
} else if len(oList) == 1 {
// service_account has MaxItems: 1
// scopes is a required field and so will always be set
oScopes := oList[0].(map[string]interface{})["scopes"].(*schema.Set)
nScopes := nList[0].(map[string]interface{})["scopes"].(*schema.Set)
scopesChange = !oScopes.Equal(nScopes)
}

// Attributes which can only be changed if the instance is stopped
if d.HasChange("machine_type") || d.HasChange("min_cpu_platform") || d.HasChange("service_account") {
if scopesChange || d.HasChange("service_account.0.email") || d.HasChange("machine_type") || d.HasChange("min_cpu_platform") {
if !d.Get("allow_stopping_for_update").(bool) {
return fmt.Errorf("Changing the machine_type, min_cpu_platform, or service_account on an instance requires stopping it. " +
"To acknowledge this, please set allow_stopping_for_update = true in your config.")
Expand Down Expand Up @@ -1309,7 +1325,7 @@ func resourceComputeInstanceUpdate(d *schema.ResourceData, meta interface{}) err
d.SetPartial("min_cpu_platform")
}

if d.HasChange("service_account") {
if d.HasChange("service_account.0.email") || scopesChange {
sa := d.Get("service_account").([]interface{})
req := &compute.InstancesSetServiceAccountRequest{ForceSendFields: []string{"email"}}
if len(sa) > 0 {
Expand Down
5 changes: 2 additions & 3 deletions google/resource_compute_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1659,13 +1659,12 @@ resource "google_compute_instance" "foobar" {
}

metadata {
bar = "baz"
bar = "baz"
startup-script = "echo Hello"
}

create_timeout = 5

metadata_startup_script = "echo Hello"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I remember making this one different on purpose - it was essential to catching some issues with metadata_startup_script vs metadata.startup-script a few weeks ago. Did you know about all that already?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think you changed it for the _basic test, which meant that the _update one now had a change on metadata_startup_script, which is a ForceNew attribute. This updates the _update test to match so the only things that change are updatable fields.


labels {
only_me = "nothing_else"
}
Expand Down