Repository navigation
Conversation
GitHub only accepts pull, triage, push, maintain, admin, or a custom repository role as a collaborator or team permission, and the provider does not validate it. A config using the UI role name (e.g. write) planned cleanly and failed with 422 on apply. Add preconditions on github_repository_collaborator and github_team_repository so plan fails with the YAML path, a hint for read/write, and the list of valid permissions. Custom roles can be declared in local.custom_repository_roles.
Team grants on archived repositories come from Terraform state, which has team_id but no team attribute, so the error message expression broke the plan. Fall back to team_id (and the resource key for collaborators). Add GitHub's built-in moderate role, reword the error so it does not claim GitHub will reject a custom role that is merely undeclared, and note the custom role upgrade step in the CHANGELOG.
terraform/tests/run.sh runs each tests/<case>.tftest.hcl against a scratch copy of the module with that case's YAML fixture (and optional state and override files) and a mocked GitHub provider. Cases cover every built-in permission, grants on archived repositories read from state, GitHub UI role names, and declared and undeclared custom roles. The Test workflow runs terraform fmt -check and these tests on pull requests and pushes that touch terraform/.
.gitignore excludes *.tfstate.*, so the fixture never reached CI. run.sh now copies tests/fixtures/<case>.state.json into place.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Adds a plan-time check that repository collaborator and team permissions in the YAML config are GitHub built-in roles (
pull,triage,moderate,push,maintain,admin, per the team and collaborator REST docs) or custom repository roles declared inlocal.custom_repository_roles.terraform/resources.tf: apreconditionongithub_repository_collaboratorandgithub_team_repository. It is skipped whenvar.resourcesis set, which only the sync script'sterraform importdoes. Grants on archived repositories come from Terraform state and are checked too; the message falls back toteam_idthere because state has noteamattribute.terraform/locals.tf:custom_repository_roles(default[], overridable inlocals_override.tf), the resultingrepository_permissionslist, and hints mapping the GitHub UI namesread→pullandwrite→push.docs/EXAMPLE.yml: notes that keys are API permission names.terraform/tests/:terraform testcases with a mocked GitHub provider, andrun.sh, which runs each case against a scratch copy of the module with that case's YAML fixture (plus optional<case>.state.jsonand<case>_override.tf)..github/workflows/test.yml: new Test workflow that runsterraform fmt -checkandterraform/tests/run.shon PRs and pushes that touchterraform/.CHANGELOG.md: the new check and workflow, plus a BREAKING note for orgs that grant custom roles.Why
The provider does not validate these permission values (custom role names are allowed), so a config using the UI role name planned cleanly and only failed with
422 Validation Failedon apply, after merge. This happened in FilOzone/github-mgmt#75 withteams: write:. With this change, the PR's plan fails instead (message shown under Validation).Validation
terraform/tests/run.sh(run in CI by the new Test workflow) covers:team_id, noteam)read, team underwritecustom_repository_rolesThe suite fails against
master(no check, so the expected failures are missing) and against this PR's first commit (moderaterejected, andUnsupported attribute "team"for the archived grant), so it catches both the original problem and the regression the review found.Also checked by hand with Terraform 1.12.0 and the real provider (dummy token,
-refresh=false): the error text below for PR #75's YAML; that apreconditioninsidelifecyclesurvives an*_override.tfthat replaces the resource'slifecycleblock; and that a bogus permission passed throughvar.resourcesskips the check. The sync script'sterraform importpath was exercised by a Codex review against a local GET-only mock of the GitHub API and succeeded.Upgrade impact
Organizations that already grant custom repository roles in their YAML will see plan fail after upgrading until they list those roles in
custom_repository_rolesinlocals_override.tf. Because the Plan workflow takes onlygithub/from the PR, a new custom role must be declared in a merged PR before a PR that grants it. The CHANGELOG says both.Not covered
terraform fmt -checkskipsterraform/bootstrap/, whoseaws.tfis already unformatted onmaster.resources_override.tfthat setspermissiondirectly on these resources bypasses the check; it validates the config value, not the provider argument.github/.schema.jsonand the TypeScript config types still allow only the built-in permission keys, so custom roles are flagged by editors using the schema. This predates the PR.