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

Don't recreate GCE instances when updating resource_policies property #5206

Conversation

hanneshayashi
Copy link
Contributor

@hanneshayashi hanneshayashi commented Sep 16, 2021

This fixes the behaviour described in hashicorp/terraform-provider-google#9981.
Basically, the change removes the ForceNew attribute from the resource_policies property of google_compute_instance and adds code to check for changes of the property. If the property changed, all old values get removed and all new values (if there are any) get added.
The change was previously submitted in hashicorp/terraform-provider-google#10029

If this PR is for Terraform, I acknowledge that I have:

  • Searched through the issue tracker for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
  • Generated Terraform, and ran make test and make lint to ensure it passes unit and linter tests.
  • Ensured that all new fields I added that can be set by a user appear in at least one example (for generated resources) or third_party test (for handwritten resources or update tests).
  • Ran relevant acceptance tests (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
  • Read the Release Notes Guide before writing my release note below.

Release Note Template for Downstream PRs (will be copied)

compute: Fixed recreation of GCE instances when updating `resource_policies` property

Regarding tests: There doesn't seem to be a test specific for this behaviour. Do you need me to create one?

@google-cla
Copy link

google-cla bot commented Sep 16, 2021

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed (or fixed any issues), please reply here with @googlebot I signed it! and we'll verify it.


What to do if you already signed the CLA

Individual signers
Corporate signers

ℹ️ Googlers: Go here for more info.

@google-cla google-cla bot added the cla: no label Sep 16, 2021
@modular-magician
Copy link
Collaborator

Oops! It looks like you're using an unknown release-note type in your changelog entries:

  • enhancement:

Please only use the types listed in https://github.com/GoogleCloudPlatform/magic-modules/blob/master/.ci/RELEASE_NOTES_GUIDE.md.

@modular-magician
Copy link
Collaborator

Hello! I am a robot who works on Magic Modules PRs.

I have detected that you are a community contributor, so your PR will be assigned to someone with a commit-bit on this repo for initial review.

Thanks for your contribution! A human will be with you soon.

@rileykarson, please review this PR or find an appropriate assignee.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 1 file changed, 32 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 1 file changed, 32 insertions(+), 2 deletions(-))

@hanneshayashi
Copy link
Contributor Author

@googlebot I signed it!

@google-cla google-cla bot added cla: yes and removed cla: no labels Sep 16, 2021
@nat-henderson nat-henderson requested review from nat-henderson and removed request for rileykarson September 16, 2021 20:42
@nat-henderson
Copy link
Contributor

Great! Let's run those tests. /gcbrun

@nat-henderson
Copy link
Contributor

Great, all those tests pass. We're ready to merge as soon as our CI pipeline is back up and healthy. :)

@nat-henderson
Copy link
Contributor

@hanneshayashi Are you able to add an update test for this, or maybe to show that you've tested it and it updates correctly?

mmv1/third_party/terraform/tests/resource_compute_instance_test.go.erb would be where to add the test if you're able.

@hanneshayashi
Copy link
Contributor Author

Sure, I'll give it a try.

@hanneshayashi
Copy link
Contributor Author

@ndmckinley I just added a test case that creates a new instance and an instance scheduler. The test has steps to add, update and remove the resource policy from the instance. I sincerely hope that I didn't mess anything up with the Magic Modules stuff. Just in case, I also pushed the test to the original PR (hashicorp/terraform-provider-google#10029).
Obviously I ran the tests locally and they pass for me. Same goes for the actual change.
Please let me know if there's anything else you need from me!

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))

@nat-henderson
Copy link
Contributor

Looks great, let's run those tests. /gcbrun

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 3 files changed, 290 insertions(+), 4 deletions(-))

@nat-henderson
Copy link
Contributor

Ah, CI node unhealthy, those happen intermittently. Let's try again. /gcbrun

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))

@nat-henderson
Copy link
Contributor

Two in a row! PR's full of bad luck. /gcbrun one more try.

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))

@hanneshayashi
Copy link
Contributor Author

Thanks for running the tests! Assuming the current failure is not due to my code and that this change can be merged soon-ish, what version can the change reasonably be expected to be included in?

@nat-henderson
Copy link
Contributor

/gcbrun

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 3 files changed, 290 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

Thanks for running the tests! Assuming the current failure is not due to my code and that this change can be merged soon-ish, what version can the change reasonably be expected to be included in?

Hashicorp CI still seems to be down, but I'll keep trying - if this goes in today, then it will go out on the 27th - otherwise, the 4th. Release cuts are usually Tuesday, for release in the afternoon PST on the following Monday (excepting holidays, surprises, bad luck - we're pretty consistent but not absolutely perfect about it).

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccBigQueryDataTable_bigtable|TestAccBigtableAppProfile_bigtableAppProfileSingleclusterExample|TestAccBigtableAppProfile_bigtableAppProfileMulticlusterExample|TestAccComputeForwardingRule_update|TestAccComputeInstance_resourcePolicyUpdate|TestAccComputeServiceAttachment_serviceAttachmentBasicExample|TestAccOrgPolicyPolicy_EnforcePolicy|TestAccOrgPolicyPolicy_FolderPolicy|TestAccOrgPolicyPolicy_OrganizationPolicy|TestAccOrgPolicyPolicy_ProjectPolicy|TestAccTags You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=206728

@nat-henderson
Copy link
Contributor

@hanneshayashi Okay! I have the tests running and I have verified there are no new failures. However, the test you added is causing this failure:

Error: Error adding resource policies: googleapi: Error 412: Compute Engine System service account service-1067888929963@compute-system.iam.gserviceaccount.com needs to have [compute.instances.start,compute.instances.stop] permissions applied in order to perform this operation., conditionNotMet
on terraform_plugin_test.tf line 7, in resource "google_compute_instance" "foobar":
7: resource "google_compute_instance" "foobar" {
--- FAIL: TestAccComputeInstance_resourcePolicyUpdate (65.31s)

Which must be a permissions difference between your env and ours. Can you tell me what perms you had to give that service account, so I can replicate it on our side? I tried compute.admin but no dice.

@hanneshayashi
Copy link
Contributor Author

Ah, my bad! I sort of assumed that there already was a test case somewhere for the instance schedulers, so I didn't think about the permissions. According to https://cloud.google.com/compute/docs/instances/schedule-instance-start-stop#before-you-begin, the Service Agent account (so service-PROJECT_NUMBER@compute-system.iam.gserviceaccount.com) needs compute.instances.start and compute.instances.stop, which is included in Compute Admin. Maybe you gave the "Compute Engine default service account" (so PROJECT_NUMBER-compute@developer.gserviceaccount.com) the permissions?

@hanneshayashi
Copy link
Contributor Author

@ndmckinley have you had a chance to take another look? I suppose I could replace the instance schedulers with something else in the test, if you have a suggestion. I just used them because they are my use-case :)
Anyway, granting the service account the roles/compute.instanceAdmin.v1 role should work according to the support page and my tests.

@nat-henderson
Copy link
Contributor

Ah, admin v1! Thank you, I'll do that.

@nat-henderson
Copy link
Contributor

/gcbrun

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccComposerEnvironment_update|TestAccComposerEnvironment_withSoftwareConfig|TestAccComputeInstance_resourcePolicyUpdate|TestAccComputeServiceAttachment_serviceAttachmentBasicExample|TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginBasicExample You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=207791

@nat-henderson
Copy link
Contributor

Great, that test passes now! Let me see what's gone wrong with the linter...

@nat-henderson
Copy link
Contributor

Hm, seems unrelated.

@nat-henderson
Copy link
Contributor

Let's rerun it and see if it was transient? /gcbrun

@modular-magician
Copy link
Collaborator

Hi! I'm the modular magician. Your PR generated some diffs in downstreams - here they are.

Diff report:

Terraform GA: Diff ( 2 files changed, 289 insertions(+), 2 deletions(-))
Terraform Beta: Diff ( 3 files changed, 290 insertions(+), 3 deletions(-))

@nat-henderson
Copy link
Contributor

Aha, yes, confirmed it is unrelated. Merging! Thanks for your contribution.

@modular-magician
Copy link
Collaborator

I have triggered VCR tests in RECORDING mode for the following tests that failed during VCR: TestAccNetworkServicesEdgeCacheOrigin_networkServicesEdgeCacheOriginAdvancedExample|TestAccNetworkServicesEdgeCacheService_networkServicesEdgeCacheServiceAdvancedExample You can view the result here: https://ci-oss.hashicorp.engineering/viewQueued.html?itemId=207804

khajduczenia pushed a commit to khajduczenia/magic-modules that referenced this pull request Oct 12, 2021
…GoogleCloudPlatform#5206)

* Don't recreate GCE instances when updating resource_policies property

* Remove ForceNew

* Add test case for update of resource_policies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants