|
| 1 | +# GitHub Enterprise Settings Example |
| 2 | + |
| 3 | +This example demonstrates how to configure GitHub Enterprise settings using the Terraform GitHub provider. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +Manage enterprise-level GitHub Actions settings with focused, composable resources: |
| 8 | + |
| 9 | +- **Actions Permissions**: Control which organizations can use GitHub Actions and what actions are allowed |
| 10 | +- **Workflow Permissions**: Manage default GITHUB_TOKEN permissions and pull request review settings |
| 11 | + |
| 12 | +## Requirements |
| 13 | + |
| 14 | +- GitHub Enterprise account |
| 15 | +- Personal access token with enterprise admin permissions |
| 16 | +- Terraform >= 0.14 |
| 17 | + |
| 18 | +## Usage |
| 19 | + |
| 20 | +1. Set your environment variables: |
| 21 | + |
| 22 | +```bash |
| 23 | +export TF_VAR_github_token="your_github_token" |
| 24 | +export TF_VAR_enterprise_slug="your-enterprise-slug" |
| 25 | +``` |
| 26 | + |
| 27 | +2. Initialize and apply: |
| 28 | + |
| 29 | +```bash |
| 30 | +terraform init |
| 31 | +terraform plan |
| 32 | +terraform apply |
| 33 | +``` |
| 34 | + |
| 35 | +## Configuration Examples |
| 36 | + |
| 37 | +### Basic Configuration - Allow All Actions |
| 38 | + |
| 39 | +```terraform |
| 40 | +# Allow all actions for all organizations |
| 41 | +resource "github_enterprise_actions_permissions" "basic" { |
| 42 | + enterprise_slug = "my-enterprise" |
| 43 | + |
| 44 | + enabled_organizations = "all" |
| 45 | + allowed_actions = "all" |
| 46 | +} |
| 47 | +
|
| 48 | +# Use restrictive workflow permissions |
| 49 | +resource "github_enterprise_actions_workflow_permissions" "basic" { |
| 50 | + enterprise_slug = "my-enterprise" |
| 51 | + |
| 52 | + default_workflow_permissions = "read" |
| 53 | + can_approve_pull_request_reviews = false |
| 54 | +} |
| 55 | +``` |
| 56 | + |
| 57 | +### Advanced Configuration - Selective Permissions |
| 58 | + |
| 59 | +```terraform |
| 60 | +# Selective actions and organizations |
| 61 | +resource "github_enterprise_actions_permissions" "advanced" { |
| 62 | + enterprise_slug = "my-enterprise" |
| 63 | + |
| 64 | + enabled_organizations = "selected" |
| 65 | + allowed_actions = "selected" |
| 66 | + |
| 67 | + allowed_actions_config { |
| 68 | + github_owned_allowed = true |
| 69 | + verified_allowed = true |
| 70 | + patterns_allowed = [ |
| 71 | + "actions/cache@*", |
| 72 | + "actions/checkout@*", |
| 73 | + "my-org/custom-action@v1" |
| 74 | + ] |
| 75 | + } |
| 76 | + |
| 77 | + enabled_organizations_config { |
| 78 | + organization_ids = [123456, 789012] # Replace with actual org IDs |
| 79 | + } |
| 80 | +} |
| 81 | +
|
| 82 | +# More permissive workflow settings |
| 83 | +resource "github_enterprise_actions_workflow_permissions" "advanced" { |
| 84 | + enterprise_slug = "my-enterprise" |
| 85 | + |
| 86 | + default_workflow_permissions = "write" |
| 87 | + can_approve_pull_request_reviews = true |
| 88 | +} |
| 89 | +``` |
| 90 | + |
| 91 | +## Available Enterprise Resources |
| 92 | + |
| 93 | +### Actions & Workflow Management |
| 94 | +- **`github_enterprise_actions_permissions`** - Controls which organizations can use GitHub Actions and which actions are allowed to run |
| 95 | +- **`github_enterprise_actions_workflow_permissions`** - Manages default GITHUB_TOKEN permissions and whether GitHub Actions can approve pull requests |
| 96 | + |
| 97 | +### Security & Analysis |
| 98 | +- **`github_enterprise_security_analysis_settings`** - Manages Advanced Security, secret scanning, and code analysis features for new repositories |
| 99 | + |
| 100 | +### Additional Resources (Available) |
| 101 | +- **`github_enterprise_actions_runner_group`** - Manages enterprise-level runner groups for GitHub Actions |
| 102 | + |
| 103 | +## Security Recommendations |
| 104 | + |
| 105 | +1. Use `"read"` workflow permissions by default |
| 106 | +2. Disable pull request review approvals for security |
| 107 | +3. Use `"selected"` actions policy to limit which actions can run |
| 108 | +4. Store tokens securely using environment variables |
| 109 | + |
| 110 | +## Configuration Reference |
| 111 | + |
| 112 | +### Actions Settings |
| 113 | + |
| 114 | +- **`actions_enabled_organizations`**: Controls which organizations can run GitHub Actions |
| 115 | + - `"all"` - All organizations in the enterprise |
| 116 | + - `"none"` - No organizations |
| 117 | + - `"selected"` - Only specified organizations (requires additional configuration) |
| 118 | + |
| 119 | +- **`actions_allowed_actions`**: Controls which actions can be run |
| 120 | + - `"all"` - All actions and reusable workflows |
| 121 | + - `"local_only"` - Only actions and workflows in the same repository/organization |
| 122 | + - `"selected"` - Only specified actions (requires additional configuration) |
| 123 | + |
| 124 | +When `actions_allowed_actions` is set to `"selected"`, you can specify: |
| 125 | + |
| 126 | +- **`actions_github_owned_allowed`**: Allow GitHub-owned actions (e.g., `actions/checkout`) |
| 127 | +- **`actions_verified_allowed`**: Allow verified Marketplace actions |
| 128 | +- **`actions_patterns_allowed`**: List of specific action patterns to allow |
| 129 | + |
| 130 | +### Workflow Settings |
| 131 | + |
| 132 | +- **`default_workflow_permissions`**: Default permissions for the GITHUB_TOKEN |
| 133 | + - `"read"` - Read-only permissions (recommended for security) |
| 134 | + - `"write"` - Read and write permissions |
| 135 | + |
| 136 | +- **`can_approve_pull_request_reviews`**: Whether GitHub Actions can approve pull request reviews |
| 137 | + - `true` - Actions can approve PR reviews |
| 138 | + - `false` - Actions cannot approve PR reviews (recommended for security) |
| 139 | + |
| 140 | +## Security Considerations |
| 141 | + |
| 142 | +1. **Workflow Permissions**: Use `"read"` permissions by default and grant `"write"` only when necessary |
| 143 | +2. **PR Approvals**: Disable `can_approve_pull_request_reviews` to prevent automated approval bypasses |
| 144 | +3. **Action Restrictions**: Use `"selected"` for `actions_allowed_actions` to limit which actions can run |
| 145 | +4. **Token Security**: Store your GitHub token securely and use environment variables |
| 146 | + |
| 147 | +## Limitations |
| 148 | + |
| 149 | +This resource currently supports a subset of enterprise settings available through the GitHub API. Additional settings like fork PR workflows, artifact retention, and self-hosted runner permissions are not yet supported by the go-github version used in this provider and will be added in future versions. |
| 150 | + |
| 151 | +## Import |
| 152 | + |
| 153 | +You can import existing enterprise settings: |
| 154 | + |
| 155 | +```bash |
| 156 | +terraform import github_enterprise_settings.example my-enterprise |
| 157 | +``` |
| 158 | + |
| 159 | +## Troubleshooting |
| 160 | + |
| 161 | +### Common Issues |
| 162 | + |
| 163 | +1. **Authentication**: Ensure your token has enterprise admin permissions |
| 164 | +2. **Enterprise Access**: Verify you have access to the specified enterprise |
| 165 | +3. **API Limits**: GitHub API has rate limits; consider adding delays for large configurations |
| 166 | + |
| 167 | +### Verification |
| 168 | + |
| 169 | +After applying, verify settings in the GitHub Enterprise dashboard: |
| 170 | +1. Go to your enterprise settings |
| 171 | +2. Navigate to "Policies" > "Actions" |
| 172 | +3. Check that the configured settings match your Terraform configuration |
0 commit comments