Skip to content

Conversation

@vedantthapa
Copy link
Contributor

Combine separate github_team_membership resource blocks for maintainers and members into one. This simplifies making changes when reconciling drift in membership.

Consider the following example, terraform plan suggests an update in-place -

[projects/copilot/FociSolutions/teams]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  ~ update in-place
Terraform will perform the following actions:
  # module.team["copilot-enabled"].github_team_membership.members["yeybr"] will be updated in-place
  ~ resource "github_team_membership" "members" {
        id       = "12815562:yeybr"
      ~ role     = "maintainer" -> "member"
        # (3 unchanged attributes hidden)
    }

However, following the suggestion from the previous plan and moving yeybr from the maintainers to members list, instead results in a destroy + create, like so -

[projects/copilot/FociSolutions/teams]
Terraform used the selected providers to generate the following execution
plan. Resource actions are indicated with the following symbols:
  + create
  - destroy
Terraform will perform the following actions:
  # module.team["copilot-enabled"].github_team_membership.maintainers["yeybr"] will be created
  + resource "github_team_membership" "maintainers" {
      + etag     = (known after apply)
      + id       = (known after apply)
      + role     = "maintainer"
      + team_id  = "12815562"
      + username = "yeybr"
    }
      # module.team["copilot-enabled"].github_team_membership.members["yeybr"] will be destroyed
  # (because key ["yeybr"] is not in for_each map)
  - resource "github_team_membership" "members" {
      - etag     = "W/\"30d522f7bff4946d257244fb97e69ad8da9049cbea62956e11b739c376d67344\"" -> null
      - id       = "12815562:yeybr" -> null
      - role     = "maintainer" -> null
      - team_id  = "12815562" -> null
      - username = "yeybr" -> null
    }

This is likely due to having separate resource definitions for each role. This PR combines the resource definitions into one via an intermediate local variable to transform the list of maintainers and members, into a single key-value pair of username => role. As a result, any suggestions for update in-place can be resolved by moving users to the right list.

@gemini-code-assist
Copy link

Summary of Changes

Hello @vedantthapa, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the Terraform configuration for managing GitHub team memberships. By consolidating the separate resource blocks for maintainers and members into a single, unified resource, the change aims to significantly improve the handling of role updates. This prevents the previous issue where changing a user's role from 'maintainer' to 'member' (or vice-versa) would result in a destructive 'destroy + create' operation, instead enabling more efficient 'update in-place' actions. The modification streamlines membership management and enhances the stability of the Terraform state.

Highlights

  • Resource Consolidation: The separate github_team_membership resource blocks for maintainers and members have been combined into a single resource block, github_team_membership.memberships.
  • Improved Role Management: A new local variable, memberships, is introduced to transform the lists of maintainers and members into a single map of username => role. This allows for in-place updates when a user's role changes, preventing destroy-and-create cycles.
  • Test Updates: The Terraform test configuration (team.tftest.hcl) has been updated to reflect the new consolidated github_team_membership.memberships resource, ensuring tests correctly validate team membership and roles.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request refactors the github_team_membership resources to use a single resource block, which is a great improvement. It correctly addresses the issue with Terraform's plan showing destroy+create instead of in-place updates when a member's role changes. The implementation is clean and uses a local variable to merge maintainers and members effectively. I have one suggestion to improve the robustness of the merge logic to prevent potential silent privilege demotion if a user is accidentally listed as both a member and a maintainer.

@vedantthapa vedantthapa merged commit 77de7dd into main Oct 1, 2025
1 check passed
@vedantthapa vedantthapa deleted the combine-github-membership-resource branch October 1, 2025 18:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants