Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
dc77805
feat: add functionality and tests for GitHub Enterprise rulesets
Ravio1i Jan 22, 2026
e251233
docs: GitHub enterprise ruleset data source and resource
Ravio1i Jan 22, 2026
9d8b390
refactor: simplify logging messages for enterprise ruleset operations…
Ravio1i Jan 23, 2026
a30f1af
feat: add description to GitHub enterprise ruleset resource and updat…
Ravio1i Jan 23, 2026
44cbb56
chore: improve error handling for setting attributes in GitHub enterp…
Ravio1i Jan 23, 2026
2d03157
refactor: streamline test check composition in GitHub enterprise rule…
Ravio1i Jan 23, 2026
09bc68d
fix: update conflicts handling for repository_name in GitHub enterpri…
Ravio1i Jan 23, 2026
8d8bfea
feat: add repository target rules and update handling in GitHub enter…
Ravio1i Jan 23, 2026
ee91775
feat: add organization_id condition support to GitHub enterprise ruleset
Ravio1i Jan 23, 2026
e2a870f
feat: add merge queue and required deployments support to GitHub ente…
Ravio1i Jan 23, 2026
f0cdf67
feat: remove merge queue and required deployments from GitHub enterpr…
Ravio1i Jan 23, 2026
6ea80ea
docs: add examples for GitHub Enterprise rulesets including branch, t…
Ravio1i Jan 23, 2026
7aacee3
feat: add customization validation for enterprise ruleset configuration
Ravio1i Jan 23, 2026
a3787e9
docs: enhance enterprise ruleset examples with repository target supp…
Ravio1i Jan 23, 2026
fda8d21
feat: add import functionality for GitHub enterprise ruleset and upda…
Ravio1i Jan 26, 2026
686da11
chore: upgrade go-github dependency to v82 and update context usage i…
Ravio1i Feb 6, 2026
07a8a49
test: update test cases to use ProviderFactories instead of Providers…
Ravio1i Feb 6, 2026
d5160d7
test: update flattenConditions tests to use context for organization_id
Ravio1i Feb 6, 2026
19f69db
feat: enhance enterprise ruleset schema with repository property cond…
Ravio1i Feb 16, 2026
59d8167
feat: add repository_property support in conditions validation and ex…
Ravio1i Feb 16, 2026
87f0adf
feat: add example branch ruleset with repository property conditions
Ravio1i Feb 16, 2026
08cc9aa
fix(enterprise_ruleset): add description to GitHub enterprise ruleset…
Ravio1i Feb 19, 2026
cb73bdb
refactor(enterprise_ruleset): streamline ruleset target types and imp…
Ravio1i Feb 19, 2026
3e7d102
refactor(ruleset): simplify validation logic and enhance conditions r…
Ravio1i Feb 19, 2026
3ac4706
test(enterprise_ruleset): add test for conflicting repository conditi…
Ravio1i Feb 19, 2026
e31eb8f
refactor(enterprise_ruleset): update validation functions to use Vali…
Ravio1i Feb 20, 2026
dcdea85
refactor(enterprise_ruleset): simplify resource creation by using poi…
Ravio1i Feb 20, 2026
21d8823
docs(enterprise_ruleset): clarify comment for repository target rules…
Ravio1i Feb 20, 2026
ac5cbe3
test(enterprise_ruleset): Replace deprecated Check/ComposeTestCheckFu…
Ravio1i Feb 20, 2026
12f7413
refactor(enterprise_ruleset): update ruleset ID handling in resource …
Ravio1i Feb 20, 2026
4fa9e60
refactor(enterprise_ruleset): improve ruleset ID handling and enforce…
Ravio1i Feb 24, 2026
2a59f50
refactor(ruleset): standardize ruleset handling across repository, or…
Ravio1i Feb 24, 2026
b613648
test(enterprise_ruleset): restructure acceptance tests into subtests …
Ravio1i Feb 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions examples/enterprise_rulesets/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# GitHub Enterprise Ruleset Examples

This directory demonstrates how to configure GitHub Enterprise rulesets using the Terraform GitHub provider.

## Overview

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

## Requirements

- GitHub Enterprise Cloud account
- Personal access token with enterprise admin permissions
- Terraform >= 0.14

## Usage

1. Set your environment variables:

```bash
export TF_VAR_github_token="your_github_token"
export TF_VAR_enterprise_slug="your-enterprise-slug"
```

2. Customize the examples by replacing `"your-enterprise"` with your actual enterprise slug

3. Apply the configuration:

```bash
terraform init
terraform plan
terraform apply
```

## Target Types

Each 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.

## Important Notes

- All enterprise rulesets require organization and repository targeting via `conditions`
- The `push` target is currently in beta and subject to change
- Branch and tag targets require `ref_name` conditions
- Repository and push targets do not use `ref_name` conditions
174 changes: 174 additions & 0 deletions examples/enterprise_rulesets/branch_rulesets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
# Example: Branch target ruleset with comprehensive branch protection rules
# This ruleset applies to branches across the enterprise

resource "github_enterprise_ruleset" "branch_protection" {
enterprise_slug = "your-enterprise"
name = "branch-protection-ruleset"
target = "branch"
enforcement = "active"

# Optional: Allow certain users/teams to bypass the ruleset
bypass_actors {
actor_id = 1
actor_type = "OrganizationAdmin"
bypass_mode = "always"
}

bypass_actors {
actor_type = "DeployKey"
bypass_mode = "always"
}

# Conditions define which organizations, repositories, and refs this ruleset applies to
conditions {
# Target all organizations in the enterprise
organization_name {
include = ["~ALL"]
exclude = []
}

# Target all repositories
repository_name {
include = ["~ALL"]
exclude = ["test-*"] # Exclude test repositories
}

# Target all branches (required for branch target)
ref_name {
include = ["~DEFAULT_BRANCH", "main", "master", "release/*"]
exclude = ["experimental/*"]
}
}

# Rules that apply to matching branches
rules {
# Prevent branch creation without bypass permission
creation = true

# Prevent branch updates without bypass permission
update = false

# Prevent branch deletion without bypass permission
deletion = true

# Require linear history (no merge commits)
required_linear_history = true

# Require signed commits
required_signatures = true

# Prevent force pushes
non_fast_forward = true

# Pull request requirements
pull_request {
dismiss_stale_reviews_on_push = true
require_code_owner_review = true
require_last_push_approval = true
required_approving_review_count = 2
required_review_thread_resolution = true
allowed_merge_methods = ["squash", "merge"]
}

# Status check requirements
required_status_checks {
strict_required_status_checks_policy = true
do_not_enforce_on_create = false

required_check {
context = "ci/build"
integration_id = 0
}

required_check {
context = "ci/test"
integration_id = 0
}
}

# Commit message pattern requirements
commit_message_pattern {
name = "Conventional Commits"
operator = "regex"
pattern = "^(feat|fix|docs|style|refactor|test|chore)(\\(.+\\))?: .{1,50}"
negate = false
}

# Commit author email pattern
commit_author_email_pattern {
name = "Corporate Email Only"
operator = "regex"
pattern = "@your-company\\.com$"
negate = false
}

# Committer email pattern
committer_email_pattern {
name = "Corporate Email Only"
operator = "regex"
pattern = "@your-company\\.com$"
negate = false
}

# Branch name pattern (only for branch target)
branch_name_pattern {
name = "Valid Branch Names"
operator = "regex"
pattern = "^(main|master|develop|feature/|bugfix/|hotfix/|release/)"
negate = false
}

# Code scanning requirements
required_code_scanning {
required_code_scanning_tool {
tool = "CodeQL"
alerts_threshold = "errors"
security_alerts_threshold = "high_or_higher"
}
}

# Copilot code review (if enabled)
copilot_code_review {
review_on_push = true
review_draft_pull_requests = false
}
}
}

resource "github_enterprise_ruleset" "branch_by_property" {
enterprise_slug = "your-enterprise"
name = "production-repos-branch-protection"
target = "branch"
enforcement = "active"

conditions {
organization_name {
include = ["~ALL"]
exclude = []
}

# Target repositories based on custom properties
repository_property {
include {
name = "environment"
property_values = ["production", "staging"]
source = "custom"
}

exclude {
name = "lifecycle"
property_values = ["deprecated", "archived"]
}
}

ref_name {
include = ["~DEFAULT_BRANCH", "refs/heads/release/*"]
exclude = []
}
}

rules {
deletion = true
non_fast_forward = true
}
}
8 changes: 8 additions & 0 deletions examples/enterprise_rulesets/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
terraform {
required_providers {
github = {
source = "integrations/github"
version = "~> 6.0"
}
}
}
154 changes: 154 additions & 0 deletions examples/enterprise_rulesets/push_rulesets.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
# Example: Push target ruleset for file and content restrictions
# This ruleset applies to all pushes across the enterprise

resource "github_enterprise_ruleset" "push_restrictions" {
enterprise_slug = "your-enterprise"
name = "push-restrictions-ruleset"
target = "push"
enforcement = "active"

# Allow deploy keys and organization admins to bypass
bypass_actors {
actor_type = "DeployKey"
bypass_mode = "always"
}

bypass_actors {
actor_id = 1
actor_type = "OrganizationAdmin"
bypass_mode = "always"
}

# Conditions define which organizations and repositories this ruleset applies to
# Note: ref_name is NOT used for push target
conditions {
# Target all organizations
organization_name {
include = ["~ALL"]
exclude = []
}

# Target all repositories
repository_name {
include = ["~ALL"]
exclude = ["sandbox-*"]
}
}

# Rules that apply to all pushes
rules {
# Restrict specific file paths from being pushed
file_path_restriction {
restricted_file_paths = [
"secrets.txt",
"*.key",
"*.pem",
".env",
"credentials/*"
]
}

# Limit maximum file size to prevent large files
max_file_size {
max_file_size = 100 # Max 100 MB
}

# Limit maximum file path length
max_file_path_length {
max_file_path_length = 255
}

# Restrict specific file extensions
file_extension_restriction {
restricted_file_extensions = [
"*.exe",
"*.dll",
"*.so",
"*.dylib",
"*.zip",
"*.tar.gz"
]
}

# Commit message pattern
commit_message_pattern {
name = "Valid Commit Message"
operator = "regex"
pattern = "^(feat|fix|docs|style|refactor|test|chore)(\\(.+\\))?: .+"
negate = false
}

# Commit author email pattern
commit_author_email_pattern {
name = "Corporate Email"
operator = "ends_with"
pattern = "@your-company.com"
negate = false
}

# Committer email pattern
committer_email_pattern {
name = "Corporate Email"
operator = "ends_with"
pattern = "@your-company.com"
negate = false
}
}
}

# Example: Security-focused push ruleset
resource "github_enterprise_ruleset" "security_push_restrictions" {
enterprise_slug = "your-enterprise"
name = "security-push-restrictions"
target = "push"
enforcement = "active"

conditions {
organization_name {
include = ["~ALL"]
exclude = []
}

repository_name {
include = ["*-prod", "*-production"]
exclude = []
}
}

rules {
# Block common secret file patterns
file_path_restriction {
restricted_file_paths = [
"*.pem",
"*.key",
"*.cert",
"*.p12",
"*.pfx",
".env",
".env.*",
"secrets.yml",
"credentials.json"
]
}

# Strict file size limits for production
max_file_size {
max_file_size = 50 # Max 50 MB
}

# Block executable and archive files
file_extension_restriction {
restricted_file_extensions = [
"*.exe",
"*.dll",
"*.so",
"*.dylib",
"*.bin",
"*.dmg"
]
}

# Require signed commits
required_signatures = true
}
}
Loading