Skip to content

Commit

Permalink
Update README for branch_protection resource
Browse files Browse the repository at this point in the history
  • Loading branch information
patrickmarabeas committed Jun 16, 2020
1 parent 7c04ec6 commit 2e39980
Showing 1 changed file with 32 additions and 25 deletions.
57 changes: 32 additions & 25 deletions website/docs/r/branch_protection.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ This resource allows you to configure branch protection for repositories in your
# the "ci/travis" context to be passing and only allow the engineers team merge
# to the branch.
resource "github_branch_protection" "example" {
repository = "${github_repository.example.name}"
branch = "master"
repository_id = github_repository.example.node_id
pattern = "master"
enforce_admins = true
required_status_checks {
Expand All @@ -29,24 +29,30 @@ resource "github_branch_protection" "example" {
required_pull_request_reviews {
dismiss_stale_reviews = true
dismissal_users = ["foo-user"]
dismissal_teams = ["${github_team.example.slug}", "${github_team.second.slug}"]
dismissal_restrictions {
actor_ids = [
data.github_user.example.node_id,
github_team.example.node_id,
]
}
}
restrictions {
users = ["foo-user"]
teams = ["${github_team.example.slug}"]
apps = ["foo-app"]
push_restrictions {
actor_ids = [github_team.example.node_id]
}
}
data "github_user" "example" {
username = "example"
}
resource "github_team" "example" {
name = "Example Name"
}
resource "github_team_repository" "example" {
team_id = "${github_team.example.id}"
repository = "${github_repository.example.name}"
team_id = github_team.example.id
repository = github_repository.example.name
permission = "pull"
}
```
Expand All @@ -55,13 +61,13 @@ resource "github_team_repository" "example" {

The following arguments are supported:

* `repository` - (Required) The GitHub repository name.
* `branch` - (Required) The Git branch to protect.
* `repository_id` - (Required) The repository associated with this branch protection rule.
* `pattern` - (Required) Identifies the protection rule pattern.
* `enforce_admins` - (Optional) Boolean, setting this to `true` enforces status checks for repository administrators.
* `require_signed_commits` - (Optional) Boolean, setting this to `true` requires all commits to be signed with GPG.
* `required_status_checks` - (Optional) Enforce restrictions for required status checks. See [Required Status Checks](#required-status-checks) below for details.
* `required_pull_request_reviews` - (Optional) Enforce restrictions for pull request reviews. See [Required Pull Request Reviews](#required-pull-request-reviews) below for details.
* `restrictions` - (Optional) Enforce restrictions for the users and teams that may push to the branch. See [Restrictions](#restrictions) below for details.
* `push_restrictions` - (Optional) Enforce restrictions for the apps, teams and users that may push to the branch. See [Push Restrictions](#push-restrictions) below for details.

### Required Status Checks

Expand All @@ -75,27 +81,28 @@ The following arguments are supported:
`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.
Always use `slug` of the team, **not** its name. Each team already **has** to have access to the repository.
* `require_code_owner_reviews`: (Optional) Require an approved review in pull requests including files with a designated code owner. Defaults to `false`.
* `required_approving_review_count`: (Optional) Require x number of approvals to satisfy branch protection requirements. If this is specified it must be a number between 1-6. This requirement matches Github's API, see the upstream [documentation](https://developer.github.com/v3/repos/branches/#parameters-1) for more information.
* `dismissal_restrictions`: (Optional) Enforce restrictions for the users and teams that may dismiss pull request reviews. See [Dismissal Restrictions](#dismissal-restrictions) below for details.

#### Dismissal Restrictions

`dismissal_restrictions` supports the following arguments:

* `actor_ids`: (Optional) The list of team or user ID's with push access.

### Restrictions
### Push Restrictions

`restrictions` supports the following arguments:
`push_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.
Always use `slug` of the team, **not** its name. Each team already **has** to have access to the repository.
* `apps`: (Optional) The list of app slugs with push access.
* `actor_ids`: (Optional) The list of app, team or user ID's with push access.

`restrictions` is only available for organization-owned repositories.
`push_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.
GitHub Branch Protection can be imported using its Node ID e.g.

```
$ terraform import github_branch_protection.terraform terraform:master
$ terraform import github_branch_protection.master 1234567
```

0 comments on commit 2e39980

Please sign in to comment.