2.6 KiB
2.6 KiB
layout | page_title | sidebar_current | description |
---|---|---|---|
github | GitHub: github_branch_protection | docs-github-resource-branch-protection | Protects a GitHub branch. |
github_branch_protection
Protects a GitHub branch.
This resource allows you to configure branch protection for repositories in your organization. When applied, the branch will be protected from forced pushes and deletion. Additional constraints, such as required status checks or restrictions on users and teams, can also be configured.
Example Usage
# Protect the master branch of the foo repository. Additionally, require that
# the "ci/travis" context to be passing and only allow the engineers team merge
# to the branch.
resource "github_branch_protection" "foo_master" {
repository = "foo"
branch = "master"
required_status_checks {
include_admins = true
strict = false
contexts = ["ci/travis"]
}
required_pull_request_reviews {
include_admins = true
}
restrictions {
teams = ["engineers"]
}
}
Argument Reference
The following arguments are supported:
repository
- (Required) The GitHub repository name.branch
- (Required) The Git branch to protect.required_status_checks
- (Optional) Enforce restrictions for required status checks. See Required Status Checks below for details.required_pull_request_reviews
- (Optional) Enforce restrictions for pull request reviews. See Required Pull Request Reviews below for details.restrictions
- (Optional) Enforce restrictions for the users and teams that may push to the branch. See Restrictions below for details.
Required Status Checks
required_status_checks
supports the following arguments:
include_admins
: (Optional) Enforce required status checks for repository administrators. Defaults tofalse
.strict
: (Optional) Require branches to be up to date before merging. Defaults tofalse
.contexts
: (Optional) The list of status checks to require in order to merge into this branch. No status checks are required by default.
Required Pull Request Reviews
required_pull_request_reviews
supports the following arguments:
include_admins
: (Optional) Enforce required status checks for repository administrators. Defaults tofalse
.
Restrictions
restrictions
supports the following arguments:
users
: (Optional) The list of user logins with push access.teams
: (Optional) The list of team slugs with push access.
restrictions
is only available for organization-owned repositories.