Skip to content

Read-after-write consistency issue on google_tags_tag_key_iam_member with conditions#16525

Merged
trodge merged 2 commits into
GoogleCloudPlatform:mainfrom
jnahelou:fix/tagIAM-conditions
Mar 3, 2026
Merged

Read-after-write consistency issue on google_tags_tag_key_iam_member with conditions#16525
trodge merged 2 commits into
GoogleCloudPlatform:mainfrom
jnahelou:fix/tagIAM-conditions

Conversation

@jnahelou
Copy link
Copy Markdown
Contributor

@jnahelou jnahelou commented Feb 25, 2026

Description

When applying an IAM binding on a tag key resource (google_tags_tag_key_iam_member) that includes a condition block, the Terraform Google provider throws the following error:

│ Error: Provider produced inconsistent result after apply
│
│ When applying changes to google_tags_tag_key_iam_member.bindings, provider "provider[\"registry.terraform.io/hashicorp/google\"]" produced an unexpected new value: Root object was present, but now absent.
│
│ This is a bug in the provider, which should be reported in the provider's own issue tracker.

Root Cause

After investigating the provider traces, the issue stems from a read-after-write inconsistency:

  • The resource is written using IAM Policy v3 (which supports conditions)
  • The subsequent read is performed using IAM Policy v1 (which does not support conditions)

As a result, the condition block is not returned by the read response (instead a hash is added in role name), causing the provider to consider the resource as absent and throwing an inconsistent state error.

Reproduction case

The error is triggered when a condition block is defined on a google_tags_tag_key_iam_member resource:

resource "google_tags_tag_key_iam_member" "bindings" {
  member  = "serviceAccount:<redacted>"
  role    = "roles/resourcemanager.tagAdmin"
  tag_key = "tagKeys/<redacted>"

  condition {
    description = "Allow the IaC PF data service account to grant the tagUser role to any principal on projects it manages."
    expression  = "api.getAttribute('iam.googleapis.com/modifiedGrantsByRole', []).hasOnly([\"roles/resourcemanager.tagUser\"])"
    title       = "only_taguser_delegation"
  }
}

Fix

The fix consists of explicitly requesting IAM Policy v3 in the getIamPolicy read request body, by adding the following payload:

{
  "options": {
    "requestedPolicyVersion": 3
  }
}
tags: fixed iam read-after-write consistency issue with conditions

@modular-magician modular-magician added the awaiting-approval Pull requests that need reviewer's approval to run presubmit tests label Feb 25, 2026
@google-cla
Copy link
Copy Markdown

google-cla Bot commented Feb 25, 2026

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

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@github-actions github-actions Bot requested a review from trodge February 25, 2026 08:45
@github-actions
Copy link
Copy Markdown

Googlers: For automatic test runs see go/terraform-auto-test-runs.

@trodge, 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.

@jnahelou jnahelou force-pushed the fix/tagIAM-conditions branch 2 times, most recently from 17c4dfe to 6dab61a Compare February 26, 2026 09:43
@jnahelou jnahelou force-pushed the fix/tagIAM-conditions branch from 6dab61a to 8e2dea0 Compare February 26, 2026 14:14
@modular-magician modular-magician added service/cloudresourcemanager-tags and removed awaiting-approval Pull requests that need reviewer's approval to run presubmit tests labels Feb 27, 2026
@modular-magician
Copy link
Copy Markdown
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 ( 5 files changed, 337 insertions(+), 6 deletions(-))
google-beta provider: Diff ( 5 files changed, 337 insertions(+), 6 deletions(-))

@modular-magician
Copy link
Copy Markdown
Collaborator

Tests analytics

Total tests: 13
Passed tests: 12
Skipped tests: 0
Affected tests: 1

Click here to see the affected service packages
  • tags

Action taken

Found 1 affected test(s) by replaying old test recordings. Starting RECORDING based on the most recent commit. Click here to see the affected tests
  • TestAccTags

Get to know how VCR tests work

@modular-magician
Copy link
Copy Markdown
Collaborator

🟢 Tests passed during RECORDING mode:
TestAccTags__tagBindingBasic [Debug log]
TestAccTags__tagBindingBasicDynamic [Debug log]
TestAccTags__tagBindingNamespaced [Debug log]
TestAccTags__tagKeyBasic [Debug log]
TestAccTags__tagKeyBasicWithAllowedValuesRegex [Debug log]
TestAccTags__tagKeyBasicWithPurposeDataGovernance [Debug log]
TestAccTags__tagKeyBasicWithPurposeGceFirewall [Debug log]
TestAccTags__tagKeyIamBinding [Debug log]
TestAccTags__tagKeyIamMember [Debug log]
TestAccTags__tagKeyIamPolicy [Debug log]
TestAccTags__tagKeyUpdate [Debug log]
TestAccTags__tagKeyUpdateAllowedValuesRegex [Debug log]
TestAccTags__tagValueBasic [Debug log]
TestAccTags__tagValueIamBinding [Debug log]
TestAccTags__tagValueIamMember [Debug log]
TestAccTags__tagValueIamPolicy [Debug log]
TestAccTags__tagValueUpdate [Debug log]
TestAccTags__tagsLocationTagBindingBasic [Debug log]
TestAccTags__tagsLocationTagBindingBasicDynamic [Debug log]
TestAccTags__tagsLocationTagBindingZonal [Debug log]
TestAccTags__tagsLocationTagBindingZonalDynamic [Debug log]
TestAccTags__tagsLocationTagBindingZonalNamespaced [Debug log]

🟢 No issues found for passed tests after REPLAYING rerun.


🟢 All tests passed!

View the build log or the debug log for each test

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Mar 2, 2026

@trodge This PR has been waiting for review for 3 weekdays. Please take a look! Use the label disable-review-reminders to disable these notifications.

@trodge trodge added this pull request to the merge queue Mar 3, 2026
Merged via the queue into GoogleCloudPlatform:main with commit f369d64 Mar 3, 2026
23 checks passed
aditikumarii-google pushed a commit to aditikumarii-google/magic-modules that referenced this pull request Mar 10, 2026
ChuAmberZhang pushed a commit to ChuAmberZhang/magic-modules that referenced this pull request Apr 29, 2026
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.

3 participants