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

Handle location tag bindings of removed resources #11857

Conversation

mKeRix
Copy link
Contributor

@mKeRix mKeRix commented Sep 27, 2024

Currently, the google_tags_location_tag_binding resource will cause any plans to fail whenever the resource (parent) it was for is deleted outside of Terraform. Specifically, it results in errors like these during the read operation:

│ Error: Error when reading or editing TagsLocationTagBinding "<some-id>": googleapi: Error 403: The caller does not have permission
│ Details:
│ [
│   {
│     "@type": "type.googleapis.com/google.rpc.ResourceInfo",
│     "description": "permission [storage.buckets.listTagBindings] required (or the resource may not exist in this location)",
│     "resourceName": "//storage.googleapis.com/projects/_/buckets/<bucket-name>"
│   }
│ ]
│
│   with google_tags_location_tag_binding.binding,
│   on main.tf line 24, in resource "google_tags_location_tag_binding" "binding":
│   24: resource "google_tags_location_tag_binding" "binding" {
│
╵

The correct Terraform behavior would be that it recognizes this resource has been removed and drops it from the state. This PR implements that behavior, allowing plan operations to succeed even when the related resource was removed externally.

I tested the change successfully against my own test files, as well as the reproduction snippet from the linked issue.

Fixes hashicorp/terraform-provider-google#15928.

Release Note Template for Downstream PRs (will be copied)

tags:  removed `google_tags_location_tag_binding` resource from the Terraform state when its parent resource has been removed outside of Terraform

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Sep 27, 2024
@mKeRix mKeRix marked this pull request as ready for review September 27, 2024 14:48
Copy link

Hello! I am a robot. Tests will require approval from a repository maintainer to run.

@ScottSuarez, a repository maintainer, has been assigned to review your changes. If you have not received review feedback within 2 business days, please leave a comment on this PR asking them to take a look.

You can help make sure that review is quick by doing a self-review and by running impacted tests locally.

@ScottSuarez ScottSuarez requested review from zli82016 and removed request for ScottSuarez September 27, 2024 16:30
@modular-magician modular-magician added service/cloudresourcemanager-tags and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Sep 27, 2024
@modular-magician
Copy link
Collaborator

Hi there, I'm the Modular magician. I've detected the following information about your changes:

Diff report

Your PR generated some diffs in downstreams - here they are.

google provider: Diff ( 1 file changed, 28 insertions(+), 2 deletions(-))
google-beta provider: Diff ( 1 file changed, 28 insertions(+), 2 deletions(-))

@modular-magician
Copy link
Collaborator

Tests analytics

Total tests: 10
Passed tests: 10
Skipped tests: 0
Affected tests: 0

Click here to see the affected service packages
  • tags

$\textcolor{green}{\textsf{All tests passed!}}$

View the build log

Copy link
Member

@zli82016 zli82016 left a comment

Choose a reason for hiding this comment

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

LGTM. I tested the fix locally and the resource google_tags_location_tag_binding is removed from the Terraform state when its parent is deleted outside of Terraform

@zli82016 zli82016 merged commit 02d6c97 into GoogleCloudPlatform:main Sep 30, 2024
14 checks passed
anavada pushed a commit to anavada/magic-modules that referenced this pull request Sep 30, 2024
karolgorc pushed a commit to karolgorc/magic-modules that referenced this pull request Oct 4, 2024
niharika-98 pushed a commit to niharika-98/magic-modules that referenced this pull request Oct 7, 2024
@mKeRix mKeRix deleted the handle-tag-bindings-for-deleted-resources branch October 7, 2024 12:50
trodge pushed a commit to trodge/magic-modules that referenced this pull request Oct 10, 2024
karolgorc pushed a commit to karolgorc/magic-modules that referenced this pull request Oct 11, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Oct 23, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Oct 24, 2024
BBBmau pushed a commit to BBBmau/magic-modules that referenced this pull request Nov 5, 2024
akshat-jindal-nit pushed a commit to akshat-jindal-nit/magic-modules that referenced this pull request Nov 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

google_tags_location_tag_binding does not behave appropriately when a binding is removed outside of tf
3 participants