Skip to content

Conversation

@vmvarela
Copy link

Add support for managing GitHub Enterprise Teams (enterprise-level teams):

Resources:

  • github_enterprise_team: create/update/delete enterprise teams
  • github_enterprise_team_membership: manage team members
  • github_enterprise_team_organizations: assign teams to organizations

Data sources:

  • github_enterprise_team: lookup by slug or ID
  • github_enterprise_teams: list all enterprise teams
  • github_enterprise_team_membership: check user membership
  • github_enterprise_team_organizations: list assigned orgs

Note: These endpoints require GitHub Enterprise Cloud with a classic PAT that has enterprise admin permissions.

Resolves #3001


Before the change?

  • No support for enterprise teams

After the change?

  • Added support for managing enterprise teams, memberships and assingments.

Pull request checklist

  • Schema migrations have been created if needed (example)
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

Please see our docs on breaking changes to help!

  • Yes
  • No

@github-actions
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@deiga
Copy link
Contributor

deiga commented Dec 18, 2025

Hey @vmvarela 👋

Thank you for your contribution!

We've started migration towards Context-aware provider functions, could you update the CRUD methods to those? So changing Read: to ReadContext: etc.

@vmvarela vmvarela marked this pull request as draft December 18, 2025 17:41
@vmvarela vmvarela marked this pull request as ready for review December 18, 2025 17:54
Copy link
Contributor

@deiga deiga left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution!

The Enteprise Teams functionality isn't yet published in the go-github SDK, but it will most likely be coming in v81. I would suggest to refactor this PR to use the upcoming release of the SDK instead of making our own API interactions.

We most likely won't get to merging this before we release v7 of the provider, where we'll hopefully quickly get to latest SDK version.

A few other notes:

  • Try to leverage ValidateDiagFunc in the Schema as much as possible, instead of failing in the CRUD provider functions on missing information. For more complex validations using a CustomizeDiff function is a good option as well. That will allow the user to get errors on plan instead of apply
  • Please add top-level Description fields to all Schemata and ensure that all Description fields contain same information as the docs pages. We'll be moving to generated docs pages in the near future

@vmvarela
Copy link
Author

Thanks for your contribution!

The Enteprise Teams functionality isn't yet published in the go-github SDK, but it will most likely be coming in v81. I would suggest to refactor this PR to use the upcoming release of the SDK instead of making our own API interactions.

We most likely won't get to merging this before we release v7 of the provider, where we'll hopefully quickly get to latest SDK version.

A few other notes:

  • Try to leverage ValidateDiagFunc in the Schema as much as possible, instead of failing in the CRUD provider functions on missing information. For more complex validations using a CustomizeDiff function is a good option as well. That will allow the user to get errors on plan instead of apply
  • Please add top-level Description fields to all Schemata and ensure that all Description fields contain same information as the docs pages. We'll be moving to generated docs pages in the near future

All It is completed @deiga

Add support for managing GitHub Enterprise Teams (enterprise-level teams):

Resources:
- github_enterprise_team: create/update/delete enterprise teams
- github_enterprise_team_membership: manage team members
- github_enterprise_team_organizations: assign teams to organizations

Data sources:
- github_enterprise_team: lookup by slug or ID
- github_enterprise_teams: list all enterprise teams
- github_enterprise_team_membership: check user membership
- github_enterprise_team_organizations: list assigned orgs

Note: These endpoints require GitHub Enterprise Cloud with a classic PAT
that has enterprise admin permissions.
- Add ValidateDiagFunc to required schema fields for early validation in plan phase
- Add validation import to resource_github_enterprise_team_membership
- This allows users to get validation errors during plan instead of apply
- Add Description field to github_enterprise_team resource schema
- Add Description field to github_enterprise_team_membership resource schema
- Descriptions match the documentation pages and will be used for generated docs
- try EnterpriseService.GetTeam via reflection to stay forward-compatible with upcoming SDK release
- keep REST fallback when SDK method is missing
- no behavior change; builds with current v67 while ready for v81
- move required field emptiness checks into ValidateDiagFunc
- remove redundant runtime empty checks in Read
- keep behavior unchanged, but surface errors during plan
…rg data sources/resources

- add top-level Description to enterprise team org data source and resource
- add ValidateDiagFunc to required fields and drop runtime empty checks
- add Description and validation to enterprise teams listing data source
Copilot AI review requested due to automatic review settings January 6, 2026 18:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This pull request adds comprehensive support for managing GitHub Enterprise Teams at the enterprise level, enabling users to create and manage teams, memberships, and organization assignments through Terraform.

Key Changes:

  • Implementation of 3 new resources for managing enterprise teams, team memberships, and organization assignments
  • Addition of 4 new data sources for querying enterprise team information
  • Custom API client utilities to handle enterprise teams endpoints (currently in preview with API version 2022-11-28)

Reviewed changes

Copilot reviewed 19 out of 19 changed files in this pull request and generated 14 comments.

Show a summary per file
File Description
github/util_enterprise_teams.go Core utility functions for interacting with GitHub's Enterprise Teams API, including CRUD operations and custom request handling for the preview API
github/resource_github_enterprise_team.go Resource implementation for creating/updating/deleting enterprise teams with support for organization selection and IdP group mapping
github/resource_github_enterprise_team_membership.go Resource for managing individual user memberships within enterprise teams
github/resource_github_enterprise_team_organizations.go Resource for assigning enterprise teams to specific organizations within the enterprise
github/data_source_github_enterprise_team.go Data source for retrieving enterprise team information by slug or ID
github/data_source_github_enterprise_teams.go Data source for listing all enterprise teams in an enterprise
github/data_source_github_enterprise_team_membership.go Data source for checking user membership status in enterprise teams
github/data_source_github_enterprise_team_organizations.go Data source for listing organizations assigned to an enterprise team
github/provider.go Provider registration for all new resources and data sources
github/resource_github_enterprise_team_test.go Acceptance tests for enterprise team resources
github/data_source_github_enterprise_team_test.go Acceptance tests for enterprise team data sources
github/data_source_github_enterprise_teams_test.go Acceptance tests for enterprise teams listing data source
website/docs/r/enterprise_team.html.markdown Documentation for the enterprise team resource
website/docs/r/enterprise_team_membership.html.markdown Documentation for the enterprise team membership resource
website/docs/r/enterprise_team_organizations.html.markdown Documentation for the enterprise team organizations resource
website/docs/d/enterprise_team.html.markdown Documentation for the enterprise team data source
website/docs/d/enterprise_teams.html.markdown Documentation for the enterprise teams listing data source
website/docs/d/enterprise_team_membership.html.markdown Documentation for the enterprise team membership data source
website/docs/d/enterprise_team_organizations.html.markdown Documentation for the enterprise team organizations data source

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@@ -0,0 +1,47 @@
---
layout: "github"
page_title: "Github: github_enterprise_team_membership"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The page_title field contains "Github" but should be "GitHub" with a capital H for proper branding consistency.

Suggested change
page_title: "Github: github_enterprise_team_membership"
page_title: "GitHub: github_enterprise_team_membership"

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,53 @@
---
layout: "github"
page_title: "Github: github_enterprise_team"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The page_title field contains "Github" but should be "GitHub" with a capital H for proper branding consistency.

Suggested change
page_title: "Github: github_enterprise_team"
page_title: "GitHub: github_enterprise_team"

Copilot uses AI. Check for mistakes.
layout: "github"
page_title: "Github: github_enterprise_team"
description: |-
Create and manages a GitHub enterprise team.
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The description contains "Create and manages" which is grammatically incorrect. It should be either "Creates and manages" or "Create and manage".

Suggested change
Create and manages a GitHub enterprise team.
Creates and manages a GitHub enterprise team.

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,45 @@
---
layout: "github"
page_title: "Github: github_enterprise_teams"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The page_title field contains "Github" but should be "GitHub" with a capital H for proper branding consistency.

Suggested change
page_title: "Github: github_enterprise_teams"
page_title: "GitHub: github_enterprise_teams"

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,38 @@
---
layout: "github"
page_title: "Github: github_enterprise_team_membership"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The page_title field contains "Github" but should be "GitHub" with a capital H for proper branding consistency.

Suggested change
page_title: "Github: github_enterprise_team_membership"
page_title: "GitHub: github_enterprise_team_membership"

Copilot uses AI. Check for mistakes.
@@ -0,0 +1,38 @@
---
layout: "github"
page_title: "Github: github_enterprise_team_organizations"
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The page_title field contains "Github" but should be "GitHub" with a capital H for proper branding consistency.

Suggested change
page_title: "Github: github_enterprise_team_organizations"
page_title: "GitHub: github_enterprise_team_organizations"

Copilot uses AI. Check for mistakes.
Comment on lines +306 to +310
// Some docs show a single object; tolerate that.
var ghErr *githubv3.ErrorResponse
if errors.As(err, &ghErr) {
return nil, err
}
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The error handling logic in listEnterpriseTeamOrganizations appears incomplete. The code checks if the error is a githubv3.ErrorResponse but then returns the error in both branches of the conditional, making the type assertion check ineffective. If the intention is to handle ErrorResponse differently, the logic should be corrected.

Suggested change
// Some docs show a single object; tolerate that.
var ghErr *githubv3.ErrorResponse
if errors.As(err, &ghErr) {
return nil, err
}

Copilot uses AI. Check for mistakes.
Type: schema.TypeInt,
Optional: true,
Computed: true,
ConflictsWith: []string{"slug"},
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The schema uses both ExactlyOneOf and ConflictsWith for the slug and team_id fields, which is redundant. ExactlyOneOf on line 29 already ensures exactly one of the two fields must be set, so ConflictsWith on line 36 is unnecessary and should be removed.

Suggested change
ConflictsWith: []string{"slug"},

Copilot uses AI. Check for mistakes.
Comment on lines +258 to +265
resp, err := deleteEnterpriseTeam(ctx, client, enterpriseSlug, teamSlug)
if err != nil {
// Already gone? That's fine, we wanted it deleted anyway.
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}
_ = resp
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The variable resp is assigned but never used (line 265 shows it's explicitly ignored with _ = resp). This statement should be removed as it serves no purpose.

Suggested change
resp, err := deleteEnterpriseTeam(ctx, client, enterpriseSlug, teamSlug)
if err != nil {
// Already gone? That's fine, we wanted it deleted anyway.
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}
_ = resp
_, err := deleteEnterpriseTeam(ctx, client, enterpriseSlug, teamSlug)
if err != nil {
// Already gone? That's fine, we wanted it deleted anyway.
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}

Copilot uses AI. Check for mistakes.
Comment on lines +112 to +118
resp, err := removeEnterpriseTeamMember(ctx, client, enterpriseSlug, enterpriseTeam, username)
if err != nil {
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}
_ = resp
Copy link

Copilot AI Jan 6, 2026

Choose a reason for hiding this comment

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

The variable resp is assigned but never used (line 118 shows it's explicitly ignored with _ = resp). This statement should be removed as it serves no purpose.

Suggested change
resp, err := removeEnterpriseTeamMember(ctx, client, enterpriseSlug, enterpriseTeam, username)
if err != nil {
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}
_ = resp
_, err := removeEnterpriseTeamMember(ctx, client, enterpriseSlug, enterpriseTeam, username)
if err != nil {
ghErr := &githubv3.ErrorResponse{}
if errors.As(err, &ghErr) && ghErr.Response.StatusCode == http.StatusNotFound {
return nil
}

Copilot uses AI. Check for mistakes.
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.

[FEAT]: Support for Github Enterprise Teams

2 participants