fix: skip github_team_members deletion when parent team is already gone#3461
fix: skip github_team_members deletion when parent team is already gone#3461nitinjain999 wants to merge 2 commits into
Conversation
|
👋 Hi, and thank you for this contribution! This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can. You can help us prioritize by joining the discussion on open issues and PRs, sharing details on the changes you need, and reviewing other contributions. 🤖 This is an automated message. |
013f2fd to
99e1360
Compare
When a github_team is destroyed alongside github_team_members, the team deletion removes all members server-side. Subsequent per-member API calls return 404 and fail loudly. Handle 404 from both getTeamID (slug-based lookup) and RemoveTeamMembershipByID (numeric ID path) by treating them as a no-op and returning early, consistent with how other resources handle missing parents. Fixes integrations#3411
99e1360 to
8b8f5f4
Compare
|
Tested against a real GitHub org ( The new subtest The existing |
There was a problem hiding this comment.
Pull request overview
These provider review instructions are being used.
This PR improves the github_team_members resource’s behavior when its parent GitHub team has been deleted (either by Terraform ordering during destroy or out-of-band), by treating “team not found” as a graceful no-op in Delete and removing the resource from state in Read to avoid perpetual diffs.
Changes:
- Update
resourceGithubTeamMembersReadto removegithub_team_membersfrom state when the parent team no longer exists (REST 404 during slug lookup, or GraphQLorganization.teamresolving to null). - Update
resourceGithubTeamMembersDeleteto treat “team not found” as a successful no-op and avoid failing on 404s. - Add an acceptance test that deletes the team out-of-band before running destroy.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
github/resource_github_team_members.go |
Adds 404-aware Read/Delete behavior to gracefully handle missing parent teams and prevent drift/perpetual diffs. |
github/resource_github_team_members_test.go |
Adds an acceptance test scenario for out-of-band team deletion prior to destroy. |
…coverage - Delete: on 404 from RemoveTeamMembershipByID, verify whether the team itself is gone before short-circuiting; if team still exists the membership was removed out-of-band so skip that user and continue the loop rather than skipping all remaining members - Test: add RefreshState step after out-of-band team deletion to assert github_team_members is removed from state by Read, covering the new getTeamSlug 404 and DatabaseId==0 guard paths
|
Addressed both Copilot review comments: Delete logic (line 297): On a 404 from Test coverage (line 102): Added a |
Resolves #3411
Before the change?
When
github_teamandgithub_team_membersare destroyed together, the team deletion removes all members server-side. The subsequentgithub_team_membersdestroy makes N individualRemoveTeamMembershipByIDAPI calls that all return 404 and fail loudly.Additionally, if a team is deleted outside of Terraform, the next
terraform planorterraform refreshwould not removegithub_team_membersfrom state — it would either error or silently return an empty member list, causing a perpetual diff.After the change?
Delete:
resourceGithubTeamMembersDeletechecks for a 404 at both points — thegetTeamID/getTeamSlugREST lookup and theRemoveTeamMembershipByIDcall — and treats either as a no-op, returning cleanly. Destroyinggithub_team+github_team_memberstogether no longer errors.Read:
resourceGithubTeamMembersReadnow removes the resource from state when the parent team is gone. It handles two paths:getTeamSlug404 (REST) — team identified by slug or numeric ID that no longer existsorganization.teamreturning null (detected viaDatabaseId == 0) — team gone after slug resolution succeededAn acceptance test is added that deletes the team out-of-band via
PreConfig, then runsDestroy: trueto exercise the delete path.Pull request checklist
Does this introduce a breaking change?