This directory demonstrates how to configure GitHub Enterprise rulesets using the Terraform GitHub provider.
Enterprise rulesets allow you to enforce policies across all organizations in your GitHub Enterprise. The examples showcase all four target types:
- Branch Target (
branch_target.tf) - Branch protection rules with PR requirements, status checks, and commit patterns - Tag Target (
tag_target.tf) - Tag protection rules with naming patterns and immutability controls - Push Target (
push_target.tf) - File restrictions, size limits, and content policies (beta feature) - Repository Target (
rulesets.tf) - Repository management rules for creation, deletion, and naming conventions
- GitHub Enterprise Cloud account
- Personal access token with enterprise admin permissions
- Terraform >= 0.14
- Set your environment variables:
export TF_VAR_github_token="your_github_token"
export TF_VAR_enterprise_slug="your-enterprise-slug"-
Customize the examples by replacing
"your-enterprise"with your actual enterprise slug -
Apply the configuration:
terraform init
terraform plan
terraform applyEach target type supports different rules:
- Branch/Tag: creation, deletion, update, signatures, linear history, PR requirements, status checks
- Push: file restrictions, size limits, file extensions, commit patterns
- Repository: creation, deletion, transfer, naming patterns, visibility controls
See the individual .tf files for detailed examples and available rules.
- All enterprise rulesets require organization and repository targeting via
conditions - The
pushtarget is currently in beta and subject to change - Branch and tag targets require
ref_nameconditions - Repository and push targets do not use
ref_nameconditions