-
Notifications
You must be signed in to change notification settings - Fork 4
GCSS-1135: Add support for GitHub environment with deployment policy #28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 4 commits
20bf48b
cbbc616
1707869
333b31e
1142cfe
3be243d
097d297
62d7c47
c5f223c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -90,8 +90,46 @@ These are the primary configuration options for each repository. | |||||
|
|
||||||
| - **`vulnerability_alerts_enabled`**: *(optional, boolean)* If `true`, vulnerability alerts are enabled. | ||||||
|
|
||||||
| - **`environments`**: *(optional, object[] [Environment](#environment-configuration))* Configuration for repository environments. Requires `feature_github_environment: true` in import config. When imported, environments are automatically managed by Terraform. | ||||||
|
|
||||||
| - **`branch_protections_v4`**: *(optional, object[] [BranchProtectionV4](#branch-protection-configuration-v4))* Configuration for branch protection rules. | ||||||
|
|
||||||
| ## Environment Configuration | ||||||
|
|
||||||
| Configure GitHub deployment environments with protection rules and reviewers. | ||||||
|
|
||||||
| **Import Control**: Set `feature_github_environment: true` in `import-config.yaml` to import environments. | ||||||
|
|
||||||
| ### Environment Fields | ||||||
|
|
||||||
| - **`environment`**: *(required, string)* Environment name | ||||||
| - **`wait_timer`**: *(optional, int)* Delay in seconds (max 43200) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this a value in minutes not seconds? Please verify
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. correct, it's in minutes (max is 30 days or 43200 minutes) - will update it are you ok with below edit?
Suggested change
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, looks good |
||||||
| - **`can_admins_bypass`**: *(optional, bool)* Admin bypass allowed (default: true) | ||||||
| - **`prevent_self_review`**: *(optional, bool)* Prevent self-approval (default: false) | ||||||
| - **`reviewers`**: *(optional, object)* | ||||||
| - **`users`**: *(string[])* GitHub usernames (max 6 total) | ||||||
| - **`teams`**: *(string[])* Team slugs (max 6 total) | ||||||
|
Comment on lines
+110
to
+111
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can be max 6 in total, not 6 per list |
||||||
|
|
||||||
| > β οΈ **IMPORTANT: Team Access Requirement** | ||||||
| > Teams specified as reviewers MUST have repository access first! | ||||||
ljuboops257 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
| > - Manually grant access at: `https://github.com/{org}/{repo}/settings/access` | ||||||
| > - Verify team access at: `https://github.com/orgs/{org}/teams/{team}/repositories` | ||||||
| > | ||||||
| > **Without repository access, Terraform will apply successfully but teams won't be added as reviewers and next plan/apply will again be shown in expected changes** | ||||||
ljuboops257 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| - **`deployment_policy`**: *(optional, object)* Controls which branches/tags can deploy to this environment | ||||||
| - **`policy_type`**: *(required, enum)* Must be one of: | ||||||
ljuboops257 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - `"protected_branches"` - Only protected branches can deploy | ||||||
| - `"selected_branches_and_tags"` - Specific branch/tag patterns can deploy | ||||||
| - **`branch_patterns`**: *(optional, string[])* Branch patterns (e.g., `["main", "release/*"]`) | ||||||
| - Only used when `policy_type` is `"selected_branches_and_tags"` | ||||||
| - Set to `null` or omit when using `"protected_branches"` | ||||||
ljuboops257 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
| - **`tag_patterns`**: *(optional, string[])* Tag patterns (e.g., `["v*"]`) | ||||||
| - Only used when `policy_type` is `"selected_branches_and_tags"` | ||||||
| - Set to `null` or omit when using `"protected_branches"` | ||||||
ljuboops257 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||||||
|
|
||||||
| **π For complete guide with examples, see [FEATURE_GITHUB_ENVIRONMENT.md](FEATURE_GITHUB_ENVIRONMENT.md)** | ||||||
|
|
||||||
| ## Template Configuration | ||||||
|
|
||||||
| Options for configuring a repository from a template. | ||||||
|
|
@@ -330,4 +368,4 @@ Options for configuring required status checks in V4. | |||||
|
|
||||||
| - **`strict`**: *(optional, boolean)* If `true`, strict status checks are enforced. | ||||||
|
|
||||||
| - **`contexts`**: *(optional, string[])* A list of required status check contexts. | ||||||
| - **`contexts`**: *(optional, string[])* A list of required status check contexts. | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this file is necessary. We have an example configuration file in the config template repo: https://github.com/G-Research/github-terraformer-configuration-template/blob/main/repos/repository.yaml.example Consider moving information to the example |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| # GitHub Environments Configuration Guide | ||
|
|
||
| This guide explains how to configure GitHub repository environments using the YAML β Terraform workflow. | ||
|
|
||
| ## Quick Start | ||
|
|
||
| ### Enable Environment Import | ||
| ```yaml | ||
| # gcss-config-repo/config/import-config.yaml | ||
| feature_github_environment: true # Required to import environments | ||
| ``` | ||
|
|
||
| ### Environment Configuration | ||
|
|
||
| ```yaml | ||
| # repos/my-app.yaml | ||
| environments: | ||
| # Option 1: Protected branches only | ||
| - environment: production | ||
| wait_timer: 300 # 5 minutes wait before deployment | ||
| can_admins_bypass: false # Admins cannot bypass | ||
| prevent_self_review: true # Cannot approve own deployments | ||
| reviewers: | ||
| users: ["octocat"] | ||
| teams: ["platform-team"] | ||
| deployment_policy: | ||
| policy_type: protected_branches | ||
|
|
||
| # Option 2: Custom branch/tag patterns | ||
| - environment: staging | ||
| deployment_policy: | ||
| policy_type: selected_branches_and_tags | ||
| branch_patterns: | ||
| - "release/*" | ||
| - "main" | ||
| tag_patterns: | ||
| - "v*" | ||
|
|
||
| # Option 3: Any branch can deploy (no restrictions) | ||
| - environment: development | ||
| # No deployment_policy = any branch can deploy | ||
| ``` | ||
|
|
||
| ## β οΈ Critical Rule: Deployment Policy Types | ||
|
|
||
| **You MUST choose ONE of these options:** | ||
|
|
||
| | Option | Configuration | Use Case | | ||
| |--------|--------------|----------| | ||
| | **Protected Branches** | `policy_type: protected_branches` | Production - only protected branches | | ||
| | **Custom Patterns** | `policy_type: selected_branches_and_tags` + patterns | Staging - specific branches/tags | | ||
| | **Any Branch** | Omit `deployment_policy` entirely | Development - no restrictions | | ||
|
|
||
| **The `policy_type` field determines which patterns are used.** | ||
|
|
||
| ## Field Reference | ||
|
|
||
| | Field | Type | Description | Default | | ||
| |-------|------|-------------|---------| | ||
| | `environment` | string | **Required** - Environment name | - | | ||
| | `wait_timer` | int | Wait time in seconds (max 43200) | 0 | | ||
| | `can_admins_bypass` | bool | Admins can bypass protections | true | | ||
| | `prevent_self_review` | bool | Prevent self-approval | false | | ||
| | `reviewers.users` | string[] | GitHub usernames (max 6 total with teams) | [] | | ||
| | `reviewers.teams` | string[] | Team slugs (max 6 total with users) | [] | | ||
| | `deployment_policy.*` | object | Deployment restrictions | - | | ||
| | β³ `policy_type` | string | `protected_branches` or `selected_branches_and_tags` | - | | ||
| | β³ `branch_patterns` | string[] | Branch patterns (only for `selected_branches_and_tags`) | [] | | ||
| | β³ `tag_patterns` | string[] | Tag patterns (only for `selected_branches_and_tags`) | [] | | ||
|
|
||
| ## Pattern Matching | ||
|
|
||
| Patterns support wildcards: | ||
| - `main` - Exact match | ||
| - `release/*` - Matches `release/1.0`, `release/2.0` | ||
| - `v*` - Matches `v1.0.0`, `v2.0.0` | ||
| - `*-final` - Matches `1.0-final`, `2.0-final` | ||
|
|
||
| ## Generated Terraform Resources | ||
|
|
||
| The YAML configuration generates: | ||
|
|
||
| 1. **Environment Resource** | ||
| ```hcl | ||
| resource "github_repository_environment" "environment" { | ||
| environment = "production" | ||
| repository = "my-app" | ||
| # ... other settings | ||
|
|
||
| deployment_branch_policy { | ||
| protected_branches = true/false | ||
| custom_branch_policies = true/false | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| 2. **Deployment Policies** (for custom patterns) | ||
| ```hcl | ||
| resource "github_repository_environment_deployment_policy" "branch_policies" { | ||
| repository = "my-app" | ||
| environment = "staging" | ||
| branch_pattern = "release/*" | ||
| } | ||
|
|
||
| resource "github_repository_environment_deployment_policy" "tag_policies" { | ||
| repository = "my-app" | ||
| environment = "staging" | ||
| tag_pattern = "v*" | ||
| } | ||
| ``` | ||
|
|
||
| ## Complete Example | ||
|
|
||
| ```yaml | ||
| environments: | ||
| - environment: production | ||
| wait_timer: 300 | ||
| can_admins_bypass: false | ||
| prevent_self_review: true | ||
| reviewers: | ||
| teams: ["platform-team"] | ||
| deployment_policy: | ||
| policy_type: protected_branches | ||
|
|
||
| - environment: staging | ||
| prevent_self_review: true | ||
| deployment_policy: | ||
| policy_type: selected_branches_and_tags | ||
| branch_patterns: ["release/*", "main"] | ||
| tag_patterns: ["v*", "rc-*"] | ||
|
|
||
| - environment: development | ||
| # No restrictions - any branch can deploy | ||
| ``` | ||
|
|
||
| ## Troubleshooting | ||
|
|
||
| | Issue | Solution | | ||
| |-------|----------| | ||
| | "reviewers: must be 6 or fewer" | Combined users + teams must be β€ 6 | | ||
| | Custom policies not working | Ensure `policy_type: selected_branches_and_tags` | | ||
| | Deployment policies not created | Check `custom_branch_policies = true` in Terraform | | ||
|
|
||
| For more configuration options, see [DEVELOPERS_GUIDE.md](DEVELOPERS_GUIDE.md) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be in another document, something like IMPORTER_DEVELOPERS_GUIDE.md or in the LOCAL_DEVELOPMENT_SETUP.md (if it's not already there).
The DEVELOPERS_GUIDE.md should focus only on the fields allowed to be set in a repo yaml config file