azuread_group_member - add eventual consistency check for Create - #1918
Open
ic-smiller wants to merge 1 commit into
Open
azuread_group_member - add eventual consistency check for Create#1918ic-smiller wants to merge 1 commit into
azuread_group_member - add eventual consistency check for Create#1918ic-smiller wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Description
groupMemberResourceCreatecallsAddMemberRefand then reads the resource back immediately. Because Microsoft Graph is eventually consistent, that read can come back with the member absent, whichgroupMemberResourceReadinterprets as the membership having been removed and so clears the ID from state. Terraform then reportsProvider produced inconsistent result after apply. The membership does exist in Azure but was never recorded in state, so the next run fails withA resource with the ID already exists, and the user has toterraform importthe orphaned membership to recover.This adds an eventual consistency check between the write and the read, so the membership link is visible before
Createreturns.The approach is the same one already used for this class of problem elsewhere in the provider:
azuread_invitation-azuread_invitation- add eventual consistency check forCreate#1844azuread_directory_role_memberandazuread_administrative_unit_memberalready perform this exact wait after adding a member refazuread_group_memberalready has the mirroredconsistency.WaitForDeletionin itsDeletefunction;Createwas simply missing the counterpartOne deliberate detail: the ID is set before the wait rather than after it. If the wait times out, that leaves a tainted resource in state rather than a membership that exists in Azure with nothing in state, which is the condition that produces the
A resource with the ID already existsfailure on the following run. Happy to reorder it to match the two resources listed above if you would rather keep them identical.Reported in #793 (open since 2022, reproduces with
for_eachover a set of members, where the concurrent writes make the race much more likely). #1810 looks like a duplicate of the same issue.Changes to existing Resource / Data Source
Testing
No new test is included, and I want to be upfront about why rather than imply coverage that is not there.
The failure is a non-deterministic race against Graph's replication delay, so an acceptance test cannot reliably demonstrate either the bug or the fix. A high-concurrency variant of
TestAccGroupMember_multipleUser(the reproduction in #793 uses ten or more members) would raise the odds of tripping it, but it would be flaky by construction and I did not think that was a fair thing to add to the suite. This matches #1844, which shipped the equivalent check forazuread_invitationwithout new test coverage. The existingTestAccGroupMember_*tests do exercise the modifiedCreatepath, includingTestAccGroupMember_requiresImport.I do not have an isolated directory available to run the acceptance tests in.
TestAccGroupMember_*provisions users, groups, applications and service principals, and I was not willing to point that at a directory that is not disposable. If a maintainer can runTEST=./internal/services/groups TESTARGS='-run TestAccGroupMember'I would appreciate it, and I am glad to act on anything it turns up.The full set of checks that CI runs on a PR pass locally against this change:
Change Log
Below please provide what should go into the changelog (if anything) conforming to the Changelog Format documented here.
azuread_group_member- add eventual consistency check forCreateThis is a (please select all that apply):
Related Issue(s)
Fixes #793
Rollback Plan
If a change needs to be reverted, we will publish an updated version of the provider.
Changes to Security Controls
No changes to security controls. The change adds a read-back poll of an existing membership using the same client and permissions already required by the resource; it does not alter what is created, what permissions are needed, or what is logged.
Note
If this PR changes meaningfully during the course of review please update the title and description as required.