[FEAT] Add support for Enterprise Cost Centers#3000
[FEAT] Add support for Enterprise Cost Centers#3000vmvarela wants to merge 10 commits intointegrations:mainfrom
Conversation
|
👋 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 |
|
We're trying to move towards using Context-aware provider functions, could you update all schemas to use those? So ReadContext etc |
13dcd40 to
1ab2c0f
Compare
There was a problem hiding this comment.
Pull request overview
This PR adds comprehensive support for GitHub Enterprise Cost Centers, enabling Terraform management of cost center resources and their assignments. The implementation addresses issue #2739 by leveraging the newly public GitHub Enterprise billing API.
Key changes:
- Introduces
github_enterprise_cost_centerresource for creating, updating, and archiving cost centers with authoritative management of user, organization, and repository assignments - Adds
github_enterprise_cost_centerandgithub_enterprise_cost_centersdata sources for querying cost center information - Implements robust resource assignment synchronization with batching (50 resources per request) and retry logic for transient failures
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| website/github.erb | Adds navigation links for the new data sources and resource |
| website/docs/r/enterprise_cost_center.html.markdown | Documents the cost center resource with examples, arguments, attributes, and import instructions |
| website/docs/d/enterprise_cost_center.html.markdown | Documents the single cost center data source for retrieving by ID |
| website/docs/d/enterprise_cost_centers.html.markdown | Documents the data source for listing cost centers with optional state filtering |
| github/util_cost_centers.go | Provides utility functions for API interactions including CRUD operations and resource assignment management |
| github/resource_github_enterprise_cost_center.go | Implements the cost center resource with full lifecycle management and authoritative assignment synchronization |
| github/provider.go | Registers the new resource and data sources with the provider |
| github/resource_github_enterprise_cost_center_test.go | Provides acceptance tests covering create, update, assignment changes, and import scenarios |
| github/data_source_github_enterprise_cost_centers_test.go | Tests the list data source with state filtering |
| github/data_source_github_enterprise_cost_centers.go | Implements the data source for listing cost centers |
| github/data_source_github_enterprise_cost_center_test.go | Tests the single cost center data source retrieval |
| github/data_source_github_enterprise_cost_center.go | Implements the data source for retrieving a specific cost center by ID |
| examples/cost_centers/main.tf | Provides a comprehensive example demonstrating resource and data source usage |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
I built and tested your branch @vmvarela and it works great! I was able to read, import, and create cost centers and resources using your examples and a few of my own. Thank you for the work. |
a3e128c to
0bdad0f
Compare
3314826 to
1d13386
Compare
deiga
left a comment
There was a problem hiding this comment.
Half-way through. Please consider if my comments could apply to other places in your changes as well, I wasn't able to comment on every duplicate thing
vmvarela
left a comment
There was a problem hiding this comment.
Thank you for the thorough review @deiga! I've addressed all the feedback. Here's a summary of the changes:
Implemented:
- ✅ Added top-level
Descriptionattribute to all resources and data sources - ✅ Removed
ctx = context.WithValue(ctx, ctxId, ...)pattern from all files - ✅ Replaced
log.Printfwithtflog.Infoand addedtflog.Warnfor 404 removals - ✅ Used
diag.Errorfinstead ofdiag.FromErr(fmt.Errorf(...)) - ✅ Create and Update no longer call Read - computed fields are set directly
- ✅ Extracted anonymous retry functions to named functions (
retryCostCenterAddResources,retryCostCenterRemoveResources) - ✅ Changed import ID separator from
/to:and usingparseTwoPartID - ✅ Replaced
stringSliceToAnySlicewith existingflattenStringList - ✅ Used
http.StatusNotFoundand other constants instead of magic numbers - ✅ Moved
is404toutil.go - ✅ Updated tests to use
providerFactoriesandskipUnlessEnterprise(t) - ✅ Added
owner = var.enterprise_slugto example provider config - ✅ Used
buildTwoPartIDin data source - ✅ Inlined check variables in tests
Regarding questions:
- The
resourcesattribute provides the raw API view whileusers,organizations,repositoriesare filtered convenience attributes. I kept both for flexibility and debugging purposes. diffStringSlicesdiffers fromsetChanges- it compares string slices directly whilesetChangesworks with Terraform state changes. They serve different purposes.- In Create, we only fetch from API after assignments are configured to populate computed fields, since we're not calling Read anymore.
All tests pass and the code compiles without errors.
b66a9c0 to
2763ff4
Compare
deiga
left a comment
There was a problem hiding this comment.
Please pay attention to what I'm asking form you and make sure to make similar changes in other places where they might apply.
Consider these also for your other PRs
52a3d8a to
5e58a8c
Compare
5e58a8c to
0143ec1
Compare
|
Have you gotten all the tests to pass locally? Can you share a screenshot of the test results? |
deiga
left a comment
There was a problem hiding this comment.
LGTM, still need review from other maintainers
stevehipwell
left a comment
There was a problem hiding this comment.
Thanks for the PR @vmvarela, I've added some general comments.
But my main review comment is that the pattern you're attempting to use for github_enterprise_cost_center is mixing concerns. Could you please separate out the assignments from the github_enterprise_cost_center resource. You could create a github_enterprise_cost_center_assignment resource to keep the authoritative pattern if it needs to span all types; but github_enterprise_cost_center_users, github_enterprise_cost_center_organizations & github_enterprise_cost_center_repositories would be the preferred pattern. This way the provider logic is more consistent and we could support non-authoritative patterns in the future.
…sources Add support for GitHub Enterprise Cost Centers with a clean separation between the cost center entity and resource assignments: Resources: - github_enterprise_cost_center: manages cost center entity (name, state) - github_enterprise_cost_center_users: authoritative user assignments - github_enterprise_cost_center_organizations: authoritative org assignments - github_enterprise_cost_center_repositories: authoritative repo assignments Data sources: - github_enterprise_cost_center: retrieve a single cost center with assignments - github_enterprise_cost_centers: list cost centers filtered by state Features: - Retry logic for transient API errors (409, 5xx) - Batching for large assignment operations (max 50 per request) - Import support for all resources Closes integrations#3000
|
Hi @stevehipwell, Done! I've separated the cost center entity from assignments into independent resources:
Shared retry logic and batching in util_enterprise_cost_center.go. All tests passing. |
…sources Add support for GitHub Enterprise Cost Centers with a clean separation between the cost center entity and resource assignments: Resources: - github_enterprise_cost_center: manages cost center entity (name, state) - github_enterprise_cost_center_users: authoritative user assignments - github_enterprise_cost_center_organizations: authoritative org assignments - github_enterprise_cost_center_repositories: authoritative repo assignments Data sources: - github_enterprise_cost_center: retrieve a single cost center with assignments - github_enterprise_cost_centers: list cost centers filtered by state Features: - Retry logic for transient API errors (409, 5xx) - Batching for large assignment operations (max 50 per request) - Import support for all resources Closes integrations#3000
31b8ad5 to
6893efd
Compare
…sources Add support for GitHub Enterprise Cost Centers with a clean separation between the cost center entity and resource assignments: Resources: - github_enterprise_cost_center: manages cost center entity (name, state) - github_enterprise_cost_center_users: authoritative user assignments - github_enterprise_cost_center_organizations: authoritative org assignments - github_enterprise_cost_center_repositories: authoritative repo assignments Data sources: - github_enterprise_cost_center: retrieve a single cost center with assignments - github_enterprise_cost_centers: list cost centers filtered by state Features: - Retry logic for transient API errors (409, 5xx) - Batching for large assignment operations (max 50 per request) - Import support for all resources Closes integrations#3000
6893efd to
7d36b30
Compare
|
@vmvarela Please stop using amend commits to address review comments. Rebasing is still strongly encouraged, but try add every new change into a new commit. Let us worry about what the git history looks like when merging a PR. It's frustratingly hard to review the changes you made after change requests and one of the major factors why I haven't been able to review your PR's in a timely manner. Edit: actually, could you rewrite the commit history to be more granular, so that we can more easily review this. Same applies to your other PRs |
7d36b30 to
25d783d
Compare
Add utility functions needed for enterprise cost center resources: - errIs404(): check if error is a GitHub 404 Not Found response - errIsRetryable(): check if error is retryable (409, 5xx) - expandStringSet(): convert schema.Set to []string - chunkStringSlice(): split slice into chunks for batching
Add util_enterprise_cost_center.go with helper functions for managing cost center assignments with proper retry logic and batching support.
Manages GitHub Enterprise cost center entities (create, read, update, archive). Includes: - Resource implementation with CRUD operations - Acceptance tests - Documentation
Authoritative management of user assignments to cost centers. Includes: - Resource implementation with batched add/remove operations - Acceptance tests - Documentation
…esource Authoritative management of organization assignments to cost centers. Includes: - Resource implementation with batched add/remove operations - Acceptance tests - Documentation
…source Authoritative management of repository assignments to cost centers. Includes: - Resource implementation with batched add/remove operations - Acceptance tests - Documentation
Add two data sources: - github_enterprise_cost_center: retrieve a cost center by ID - github_enterprise_cost_centers: list cost centers with optional state filter Includes: - Data source implementations - Acceptance tests - Documentation
- Register 4 resources in provider.go: - github_enterprise_cost_center - github_enterprise_cost_center_users - github_enterprise_cost_center_organizations - github_enterprise_cost_center_repositories - Register 2 data sources in provider.go: - github_enterprise_cost_center - github_enterprise_cost_centers - Add navigation links in website/github.erb T_EDITOR=true git rebase --continue t status
Add example Terraform configuration demonstrating how to: - Create a cost center - Assign users, organizations, and repositories - Use data sources to query cost centers
Update import paths from go-github/v81 to go-github/v82 to match the current version in upstream/main.
24aba77 to
a704658
Compare

Resolves #2739
Before the change?
After the change?
NOTE: This API (billing) has no support for APP or fine-grained tokens.
Pull request checklist
Does this introduce a breaking change?
Please see our docs on breaking changes to help!