Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ To import a **forked** repository into the organization:
> πŸ“ We are working on improving this so that the user has the same experience as when creating a new repo

> [!IMPORTANT]
> All important attributes are documented in the [Developer's Guide](DEVELOPERS_GUIDE.md).
> All important attributes are documented in the [Developer's Guide](docs/DEVELOPERS_GUIDE.md).
37 changes: 36 additions & 1 deletion DEVELOPERS_GUIDE.md β†’ docs/DEVELOPERS_GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,43 @@ 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.
Copy link
Contributor

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


### Environment Fields

- **`environment`**: *(required, string)* Environment name
- **`wait_timer`**: *(optional, int)* Delay in seconds (max 43200)
Copy link
Contributor

@pavlovic-ivan pavlovic-ivan Nov 21, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this a value in minutes not seconds? Please verify

Copy link
Contributor Author

@ljuboops257 ljuboops257 Nov 24, 2025

Choose a reason for hiding this comment

The 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
verifyuing on my org for demo1 repo and its actual config

are you ok with below edit?

Suggested change
- **`wait_timer`**: *(optional, int)* Delay in seconds (max 43200)
- **`wait_timer`**: *(optional, int)* Delay in minutes (max 43200 or 30 days)

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor

Choose a reason for hiding this comment

The 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!
> - 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 show them as proposed changes**

- **`deployment_policy`**: *(optional, object)* Controls which branches/tags can deploy to this environment
- **`policy_type`**: *(required, string)* Must be one of:
- `"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"`
- **`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"`

**πŸ“– For complete guide with examples, see [FEATURE_GITHUB_ENVIRONMENT.md](FEATURE_GITHUB_ENVIRONMENT.md)**

## Template Configuration

Options for configuring a repository from a template.
Expand Down Expand Up @@ -330,4 +365,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.
144 changes: 144 additions & 0 deletions docs/FEATURE_GITHUB_ENVIRONMENT.md
Copy link
Contributor

Choose a reason for hiding this comment

The 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)
Loading