Skip to content

Instantly share code, notes, and snippets.

@prabhu
Created July 18, 2020 13:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save prabhu/dee869d761f2ac53e3574df27ef57761 to your computer and use it in GitHub Desktop.
Save prabhu/dee869d761f2ac53e3574df27ef57761 to your computer and use it in GitHub Desktop.
Protect github branches, mandate status checks with Terraform
# Protect the master branch. Enforce that ci/tests and shiftleft should pass to allow merges
# Allow PR to be dismissed by sem-user and managers team
resource "github_branch_protection" "protect_master" {
repository = "${github_repository_name}"
branch = "master"
enforce_admins = true
require_signed_commits = false
required_status_checks {
strict = false
contexts = ["ci/tests", "shiftleft"]
}
required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_users = ["sem-user"]
dismissal_teams = ["${github_team.managers.slug}"]
}
restrictions {
users = ["sem-user"]
teams = ["${github_team.managers.slug}"]
}
}
resource "github_team" "managers" {
name = "SEM team"
}
resource "github_team_repository" "example" {
team_id = "${github_team.managers.id}"
repository = "${github_repository_name}"
permission = "pull"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment