Skip to content

fix: read immediate github_team_members only, not child-team members - #3498

Merged
stevehipwell merged 1 commit into
mainfrom
robert-crandall/review-pr-3461
Jun 23, 2026
Merged

stevehipwell merged 1 commit into
mainfrom
robert-crandall/review-pr-3461

Conversation

@robert-crandall

@robert-crandall robert-crandall commented Jun 18, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #3497

Before the change?

#3499 refactored github_team_members and added a team_with_child_team regression test, but its Read path (getTeamMembers) still uses the REST list-team-members endpoint. That endpoint always includes members inherited from child teams and has no immediate-only option (the go-github TeamListTeamMembersOptions only exposes a role filter). So for organizations with nested teams, Read pulls in inherited members the user never configured, breaking the authoritative member set and surfacing drift. The team_with_child_team test currently fails on main for this reason.

After the change?

getTeamMembers now uses the GraphQL API with membership: IMMEDIATE, which returns only the team's direct members. A null team node (team deleted out-of-band) is mapped to a 404 github.ErrorResponse, so the existing Read/Delete handling still removes the resource from state - preserving the team_delete_handled behaviour.

getTeamMembers and updateTeamMembers now take *Owner so the read path can reach the v4 (GraphQL) client while membership add/remove keep using the v3 (REST) client.

This is rebased onto main (post-#3499). Because #3499 rewrote the resource, this is now a single focused commit re-deriving the fix against the new getTeamMembers structure rather than the original pre-#3499 diff.

How I verified it

I exercised the real getTeamMembers function (not a copy) against a live nested team (integrations/hubbers) by temporarily wiring it through getTestMeta:

  • getTeamMembers (new GraphQL IMMEDIATE path) returned 14 members (immediate only).
  • The old REST role-filtered approach returned 40 for the same team - the extra 26 are inherited child-team members. This is exactly the inflation that fails team_with_child_team's SetSizeExact assertion on main.
  • A non-existent team slug returned a 404 github.ErrorResponse, confirming the GraphQL null-node -> 404 mapping that keeps team_delete_handled working (Read removes from state).

Static checks: go build, go vet, gofmt -l, go test -run TestAccGithubTeamMembers (compiles + skips without creds), golangci-lint run ./github/ (0 issues), and the repo's strict linter (forcetypeassert) against the changed code (0 issues).

What I did NOT verify

  • I did not run the full TF_ACC acceptance suite end-to-end (no org-write credentials here; team_with_child_team needs two org members + a child team). My verification drives the real getTeamMembers against a live nested team, which proves the immediate-vs-all behaviour and the 404 mapping, but it is not the literal Terraform acceptance run.

Does this introduce a breaking change?

  • Yes
  • No

@github-actions

Copy link
Copy Markdown

👋 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.

@stevehipwell

Copy link
Copy Markdown
Collaborator

@robert-crandall I think the first thing to do here is to add a test for the regression, I'll take a look at the tests and open a PR to modernize the existing ones and add a test for ignoring child team members.

@deiga deiga left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Good catch! Do we have a regression test for this?

Comment thread github/resource_github_team_members.go Resolved
@stevehipwell stevehipwell added this to the v6.13.0 milestone Jun 22, 2026
@stevehipwell

Copy link
Copy Markdown
Collaborator

@robert-crandall you should be able to rebase this onto main and confirm that it fixes the currently failing regression test I added in #3499.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes #3497: after #3499 refactored github_team_members, its Read path used the REST list-team-members endpoint, which always includes members inherited from child teams (it has no immediate-only option). For organizations with nested teams this surfaced inherited members as drift on a resource that manages membership authoritatively. The fix moves the Read path back to the GraphQL API with membership: IMMEDIATE, restoring the pre-#3461 immediate-only semantics while keeping #3461's clean 404 handling.

Changes:

  • getTeamMembers now queries the v4 (GraphQL) client with members(membership: IMMEDIATE, ...) and paginates via PageInfo, returning only direct team members.
  • A null team node (team deleted out-of-band) is mapped to a 404 github.ErrorResponse, preserving the existing Read "remove from state" and Delete "already gone" behavior.
  • getTeamMembers and updateTeamMembers now accept *Owner (so Read can reach v4client while add/remove keep using the v3 REST client); all call sites updated consistently.
Show a summary per file
File Description
github/resource_github_team_members.go Switches the member-read path to GraphQL IMMEDIATE membership with pagination and null-team→404 mapping; threads *Owner through getTeamMembers/updateTeamMembers and updates all callers.

Verification notes: The GraphQL query shape, cursor pattern ((*githubv4.String)(nil) initial cursor, looping on PageInfo.HasNextPage), and the role lowercasing all match existing conventions (e.g., data_source_github_team.go uses the same membership: IMMEDIATE query). The IMMEDIATE role enum values map cleanly to the schema's member/maintainer values, and the team_with_child_team / team_delete_handled acceptance tests cover the changed behavior. No schema/state shape changes, so this is a backward-compatible bug fix. No blocking findings found.

Copilot's findings

  • Files reviewed: 1/1 changed files
  • Comments generated: 0

@robert-crandall

Copy link
Copy Markdown
Contributor Author

@robert-crandall you should be able to rebase this onto main and confirm that it fixes the currently failing regression test I added in #3499.

@stevehipwell Done!

@robert-crandall
robert-crandall marked this pull request as ready for review June 22, 2026 18:57

@stevehipwell stevehipwell left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@stevehipwell
stevehipwell enabled auto-merge (squash) June 23, 2026 13:06
@stevehipwell

Copy link
Copy Markdown
Collaborator

@robert-crandall please could you rebase so this can be merged.

The Read path (getTeamMembers) used the REST list-team-members endpoint,
which always includes members inherited from child teams and has no
immediate-only option. For organizations with nested teams this surfaced
inherited members as drift, and broke the github_team_members member set
that is meant to be authoritative.

Switch getTeamMembers to the GraphQL API with membership:IMMEDIATE so
only direct members are returned. A null team node is mapped to a 404
github.ErrorResponse so the existing Read/Delete handling still removes
the resource from state when the team is deleted out-of-band.

getTeamMembers and updateTeamMembers now take *Owner so they can reach
the v4 (GraphQL) client for reads while still using the v3 client for
membership add/remove.

Fixes the team_with_child_team regression test added in #3499.

Co-authored-by: Copilot <[email protected]>
@robert-crandall
robert-crandall force-pushed the robert-crandall/review-pr-3461 branch from 36608aa to 087a76d Compare June 23, 2026 15:12
@stevehipwell
stevehipwell merged commit 614a772 into main Jun 23, 2026
10 checks passed
@stevehipwell
stevehipwell deleted the robert-crandall/review-pr-3461 branch June 23, 2026 15:14
@rilical rilical added the Type: Bug Something isn't working as documented label Jul 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Bug Something isn't working as documented

Projects

None yet

Development

Successfully merging this pull request may close these issues.

github_team_members: Read includes child-team members

5 participants