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"
  enforce_admins = true

  required_status_checks {
    strict = false
    contexts = ["ci/travis"]
  }

  required_pull_request_reviews {
    dismiss_stale_reviews = true
    dismissal_users = ["foo-user"]
    dismissal_teams = ["admins", "engineers"]
  }

  restrictions {
    users = ["foo-user"]
    teams = ["engineers"]
  }
}

Argument Reference

The following arguments are supported:

Required Status Checks

required_status_checks supports the following arguments:

  • strict: (Optional) Require branches to be up to date before merging. Defaults to false.
  • 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:

  • dismiss_stale_reviews: (Optional) Dismiss approved reviews automatically when a new commit is pushed. Defaults to false.
  • dismissal_users: (Optional) The list of user logins with dismissal access
  • dismissal_teams: (Optional) The list of team slugs with dismissal access
  • require_code_owner_reviews: (Optional) Require an approved review in pull requests including files with a designated code owner. Defaults to false.

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.

Import

Github Branch Protection can be imported using an id made up of repository:branch, e.g.

$ terraform import github_branch_protection.terraform terraform:master

© 2018 HashiCorp
Licensed under the MPL 2.0 License.
https://www.terraform.io/docs/providers/github/r/branch_protection.html