Skip to content

feat: add fork-PR contributor approval resources and data sources#3446

Open
donicrosby wants to merge 1 commit into
integrations:mainfrom
donicrosby:feat/actions-fork-pr-contributor-approval
Open

feat: add fork-PR contributor approval resources and data sources#3446
donicrosby wants to merge 1 commit into
integrations:mainfrom
donicrosby:feat/actions-fork-pr-contributor-approval

Conversation

@donicrosby
Copy link
Copy Markdown

Resolves #3445


Before the change?

The provider has no resource or data source for the GitHub fork PR contributor approval policy ("Fork pull request workflows from outside collaborators" in the Actions general settings UI). The setting can only be managed through the UI or out-of-band gh api calls, with no Terraform drift detection.

After the change?

Four new building blocks wrap the existing GitHub REST endpoints:

Type Name Wraps
resource github_actions_repository_fork_pr_contributor_approval PUT /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval
resource github_actions_organization_fork_pr_contributor_approval PUT /orgs/{org}/actions/permissions/fork-pr-contributor-approval
data source github_actions_repository_fork_pr_contributor_approval GET /repos/{owner}/{repo}/actions/permissions/fork-pr-contributor-approval
data source github_actions_organization_fork_pr_contributor_approval GET /orgs/{org}/actions/permissions/fork-pr-contributor-approval

Each accepts the documented approval_policy enum: first_time_contributors_new_to_github, first_time_contributors, all_external_contributors.

Implementation notes

  • go-github v86 already exposes the matching *ActionsService methods (GetForkPRContributorApprovalPermissions / Update... and the Organization* variants). The provider change is a thin wrapper — no SDK work was needed.
  • Patterned on resource_github_actions_repository_access_level (repo-level) and resource_github_actions_organization_permissions (org-level).
  • The API has no "off" state for this policy. On Delete, the resource resets to the GitHub-documented default (first_time_contributors), mirroring the precedent in github_actions_organization_permissions (which resets to all on Delete).
  • The data sources let callers read current state before deciding to declare a managing resource — useful for opt-in patterns where most repos should retain their existing setting.

Test results

Acceptance tests run against an organization-mode test token:

Test Duration Result
TestAccGithubActionsRepositoryForkPRContributorApproval (3 enum cases) 60.9s PASS
TestAccGithubActionsRepositoryForkPRContributorApprovalDataSource 24.3s PASS
TestAccGithubActionsOrganizationForkPRContributorApproval (3 enum cases) 29.8s PASS
TestAccGithubActionsOrganizationForkPRContributorApprovalDataSource 12.6s PASS

make fmt, make lint, go build ./..., go vet ./github/ all clean. make validatedocs was not run locally because the dev environment lacks a terraform binary; rendered docs were authored to match the templates and CI will validate.

The repo-level tests use visibility = "public" because configuring fork-pr-contributor-approval on private repos returns 422 unless the org's fork-pr-workflows-private-repos setting has fork-PR workflows enabled. Public repos exercise the documented happy-path without that prerequisite. The behavior is noted in the rendered resource docs with a pointer to the related fork-pr-workflows-private-repos endpoint.

Pull request checklist

  • Schema migrations have been created if needed — N/A, new resources only
  • Tests for the changes have been added — resource + data source × repo + org, four files
  • Docs have been reviewed and added / updated if needed — docs/{resources,data-sources}/… + templates/… + examples/…

Does this introduce a breaking change?

  • Yes
  • No

New resources and data sources; no changes to existing surface area.


AI Use Disclosure

Per the project's AI Use Policy: this PR was implemented with AI assistance. I personally read the SDK signatures, reviewed each file against the existing access_level and organization_permissions patterns, ran the acceptance test suite end-to-end against a sandbox org I control, and verified the rendered docs match the templates. The motivation came from a real internal need (a Terraform-managed baseline for "external contributor workflows require maintainer approval before they run" on public repos in our org).

@github-actions
Copy link
Copy Markdown

👋 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! 🚀

@github-actions github-actions Bot added the Type: Feature New feature or request label May 25, 2026
Wrap the GitHub REST `actions/permissions/fork-pr-contributor-approval`
endpoints (repo + org) in four new Terraform building blocks:

- resource `github_actions_repository_fork_pr_contributor_approval`
- resource `github_actions_organization_fork_pr_contributor_approval`
- data source `github_actions_repository_fork_pr_contributor_approval`
- data source `github_actions_organization_fork_pr_contributor_approval`

Each accepts `approval_policy` in the three GitHub-documented enum values
(`first_time_contributors_new_to_github`, `first_time_contributors`,
`all_external_contributors`).

The API has no "off" state for this policy. On Delete, the resource resets
the policy to GitHub's documented default (`first_time_contributors`) to
avoid leaving non-default residual state, matching the precedent set by
`github_actions_organization_permissions` Delete (which resets to `all`).

go-github already exposes the matching service methods on `*ActionsService`
(GetForkPRContributorApprovalPermissions / Update... and the Organization*
variants), so this is purely a provider-side wrapper.

New resources are implemented with context-aware CRUD functions
(`CreateContext` / `ReadContext` / `UpdateContext` / `DeleteContext`
returning `diag.Diagnostics`) per the migration tracked in integrations#2996, rather
than copying the legacy pattern from the nearby `access_level` and
`organization_permissions` resources that are themselves on that
migration's to-do list.

Acceptance test notes:
- Repo-level tests use `visibility = "public"` because configuring
  `fork-pr-contributor-approval` on private repos returns 422 when the
  org's `fork-pr-workflows-private-repos` setting has fork-PR workflows
  disabled. Public repos exercise the endpoint without that prerequisite.
- The repo-level test allows both `individual` and `organization` auth
  modes so it can be exercised against an org-scoped test token.

Doc generation was authored against `make generatedocs` templates and the
rendered output is included; `make validatedocs` was not run locally because
the dev environment lacks a `terraform` binary. CI will validate.
@donicrosby donicrosby force-pushed the feat/actions-fork-pr-contributor-approval branch from a8495f7 to 4cfdf42 Compare May 25, 2026 21:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Add github_actions_*_fork_pr_contributor_approval resources and data sources

1 participant