Skip to content

Commit ee6001a

Browse files
authored
Merge pull request #139 from mineiros-io/mariux/bpv4
feat!: Add support for v4 branch protections
2 parents f94103f + 3e4e6e2 commit ee6001a

File tree

8 files changed

+492
-144
lines changed

8 files changed

+492
-144
lines changed

.pre-commit-config.yaml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,5 @@ repos:
88
- id: tflint
99
- id: phony-targets
1010
- id: terradoc-validate
11-
- id: golangci-lint
1211
- id: terradoc-fmt
1312
- id: terradoc-generate
14-
# - id: terramate-generate
15-
- id: markdown-link-check
16-
args: ['-p'] # When adding the -p flag, markdown-link-check will always with an exit code 0, even if dead links are found
17-
verbose: true # Forces the output of the hook to be printed even when the hook passes.

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
## [0.18.0]
11+
12+
### Added
13+
14+
- Add support for v4 branch protections.
15+
16+
### Removed
17+
18+
- BREAKING CHANGE: Remove deprectated variable `branch_protections` please use `branch_protections_v3` instead.
19+
20+
### Deprecated
21+
22+
- Mark `var.defaults` as deprecated. This variable was introduced and used before Terraform Module `for_each` was available.
23+
1024
## [0.17.0]
1125

1226
### Added
@@ -385,7 +399,8 @@ Please review plans and report regressions and issues asap so we can improve doc
385399
- This is the initial release of our GitHub Repository module with support for
386400
creating and managing GitHub Repositories for Organizations.
387401

388-
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.17.0...HEAD
402+
[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.18.0...HEAD
403+
[0.18.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.17.0...v0.18.0
389404
[0.17.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.2...v0.17.0
390405
[0.16.2]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.1...v0.16.2
391406
[0.16.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.16.0...v0.16.1

README.md

Lines changed: 143 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ A [Terraform] module for creating a public or private repository on [Github].
2828
- [Collaborator Configuration](#collaborator-configuration)
2929
- [Branches Configuration](#branches-configuration)
3030
- [Deploy Keys Configuration](#deploy-keys-configuration)
31-
- [Branch Protections Configuration](#branch-protections-configuration)
31+
- [Branch Protections v3 Configuration](#branch-protections-v3-configuration)
32+
- [Branch Protections v4 Configuration](#branch-protections-v4-configuration)
3233
- [Issue Labels Configuration](#issue-labels-configuration)
3334
- [Projects Configuration](#projects-configuration)
3435
- [Webhooks Configuration](#webhooks-configuration)
@@ -103,25 +104,12 @@ Most basic usage creating a new private github repository.
103104
```hcl
104105
module "repository" {
105106
source = "mineiros-io/repository/github"
106-
version = "~> 0.16.0"
107+
version = "~> 0.18.0"
107108
108109
name = "terraform-github-repository"
109110
license_template = "apache-2.0"
110111
gitignore_template = "Terraform"
111112
}
112-
113-
provider "github" {}
114-
115-
terraform {
116-
required_version = "~> 1.0"
117-
118-
required_providers {
119-
github = {
120-
source = "integrations/github"
121-
version = "~> 4.0"
122-
}
123-
}
124-
}
125113
```
126114

127115
## Module Argument Reference
@@ -136,32 +124,10 @@ See [variables.tf] and [examples/] for details and use-cases.
136124

137125
- [**`defaults`**](#var-defaults): *(Optional `object(defaults)`)*<a name="var-defaults"></a>
138126

139-
A object of default settings to use instead of module defaults for top-level arguments.
140-
See below for a list of supported arguments.
141-
142-
This is a special argument to set various defaults to be reused for multiple repositories.
143-
144-
The following top-level arguments can be set as defaults:
145-
`homepage_url`,
146-
`visibility`,
147-
`has_issues`,
148-
`has_projects`,
149-
`has_wiki`,
150-
`allow_merge_commit`,
151-
`allow_rebase_merge`,
152-
`allow_squash_merge`,
153-
`allow_auto_merge`,
154-
`has_downloads`,
155-
`auto_init`,
156-
`gitignore_template`,
157-
`license_template`,
158-
`default_branch`,
159-
`topics`,
160-
`issue_labels_create`,
161-
`issue_labels_merge_with_github_labels`.
162-
163-
Module defaults are used for all arguments that are not set in `defaults`.
164-
Using top level arguments override defaults set by this argument.
127+
DEPRECATED:
128+
This variable will be removed in future releases.
129+
It was needed in times when Terraform Module for each was not available to provide default values for multiple repositories.
130+
Please convert your code accordingly to stay compatible with future releases.
165131

166132
Default is `{}`.
167133

@@ -528,11 +494,11 @@ This is due to some terraform limitation and we will update the module once terr
528494

529495
Default is `"md5(key)"`.
530496

531-
#### Branch Protections Configuration
497+
#### Branch Protections v3 Configuration
532498

533499
- [**`branch_protections_v3`**](#var-branch_protections_v3): *(Optional `list(branch_protection_v3)`)*<a name="var-branch_protections_v3"></a>
534500

535-
This resource allows you to configure branch protection for repositories in your organization.
501+
This resource allows you to configure v3 branch protection for repositories in your organization.
536502
When applied, the branch will be protected from forced pushes and deletion.
537503
Additional constraints, such as required status checks or restrictions on users and teams, can also be configured.
538504

@@ -645,13 +611,144 @@ This is due to some terraform limitation and we will update the module once terr
645611

646612
Default is `[]`.
647613

648-
- [**`branch_protections`**](#var-branch_protections): *(Optional `list(branch_protection_v3)`)*<a name="var-branch_protections"></a>
614+
#### Branch Protections v4 Configuration
615+
616+
- [**`branch_protections_v4`**](#var-branch_protections_v4): *(Optional `list(branch_protection_v4)`)*<a name="var-branch_protections_v4"></a>
617+
618+
This resource allows you to configure v4 branch protection for repositories in your organization.
619+
620+
Each element in the list is a branch to be protected and the value the corresponding to the desired configuration for the branch.
621+
622+
When applied, the branch will be protected from forced pushes and deletion.
623+
Additional constraints, such as required status checks or restrictions on users and teams, can also be configured.
649624

650-
**_DEPRECATED_** To ensure compatibility with future versions of this module, please use `branch_protections_v3`.
651-
This argument is ignored if `branch_protections_v3` is used. Please see `branch_protections_v3` for supported attributes.
625+
**_NOTE:_** May conflict with v3 branch protections if used for the same branch.
652626

653627
Default is `[]`.
654628

629+
Each `branch_protection_v4` object in the list accepts the following attributes:
630+
631+
- [**`pattern`**](#attr-branch_protections_v4-pattern): *(**Required** `string`)*<a name="attr-branch_protections_v4-pattern"></a>
632+
633+
Identifies the protection rule pattern.
634+
635+
- [**`_key`**](#attr-branch_protections_v4-_key): *(Optional `string`)*<a name="attr-branch_protections_v4-_key"></a>
636+
637+
An alternative key to use in `for_each` resource creation.
638+
Defaults to the value of `var.pattern`.
639+
640+
- [**`allows_deletions`**](#attr-branch_protections_v4-allows_deletions): *(Optional `bool`)*<a name="attr-branch_protections_v4-allows_deletions"></a>
641+
642+
Setting this to `true` to allow the branch to be deleted.
643+
644+
Default is `false`.
645+
646+
- [**`allows_force_pushes`**](#attr-branch_protections_v4-allows_force_pushes): *(Optional `bool`)*<a name="attr-branch_protections_v4-allows_force_pushes"></a>
647+
648+
Setting this to `true` to allow force pushes on the branch.
649+
650+
Default is `false`.
651+
652+
- [**`blocks_creations`**](#attr-branch_protections_v4-blocks_creations): *(Optional `bool`)*<a name="attr-branch_protections_v4-blocks_creations"></a>
653+
654+
Setting this to `true` will block creating the branch.
655+
656+
Default is `false`.
657+
658+
- [**`enforce_admins`**](#attr-branch_protections_v4-enforce_admins): *(Optional `bool`)*<a name="attr-branch_protections_v4-enforce_admins"></a>
659+
660+
Keeping this as `true` enforces status checks for repository administrators.
661+
662+
Default is `true`.
663+
664+
- [**`push_restrictions`**](#attr-branch_protections_v4-push_restrictions): *(Optional `list(string)`)*<a name="attr-branch_protections_v4-push_restrictions"></a>
665+
666+
The list of actor Names/IDs that may push to the branch.
667+
Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
668+
669+
Default is `[]`.
670+
671+
- [**`require_conversation_resolution`**](#attr-branch_protections_v4-require_conversation_resolution): *(Optional `bool`)*<a name="attr-branch_protections_v4-require_conversation_resolution"></a>
672+
673+
Setting this to true requires all conversations on code must be resolved before a pull request can be merged.
674+
675+
Default is `false`.
676+
677+
- [**`require_signed_commits`**](#attr-branch_protections_v4-require_signed_commits): *(Optional `bool`)*<a name="attr-branch_protections_v4-require_signed_commits"></a>
678+
679+
Setting this to true requires all commits to be signed with GPG.
680+
681+
Default is `false`.
682+
683+
- [**`required_linear_history`**](#attr-branch_protections_v4-required_linear_history): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_linear_history"></a>
684+
685+
Setting this to true enforces a linear commit Git history, which prevents anyone from pushing merge commits to a branch.
686+
687+
Default is `false`.
688+
689+
- [**`required_pull_request_reviews`**](#attr-branch_protections_v4-required_pull_request_reviews): *(Optional `object(required_pull_request_reviews)`)*<a name="attr-branch_protections_v4-required_pull_request_reviews"></a>
690+
691+
Enforce restrictions for pull request reviews.
692+
693+
The `required_pull_request_reviews` object accepts the following attributes:
694+
695+
- [**`dismiss_stale_reviews`**](#attr-branch_protections_v4-required_pull_request_reviews-dismiss_stale_reviews): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-dismiss_stale_reviews"></a>
696+
697+
Dismiss approved reviews automatically when a new commit is pushed.
698+
699+
Default is `true`.
700+
701+
- [**`restrict_dismissals`**](#attr-branch_protections_v4-required_pull_request_reviews-restrict_dismissals): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-restrict_dismissals"></a>
702+
703+
Restrict pull request review dismissals.
704+
705+
- [**`dismissal_restrictions`**](#attr-branch_protections_v4-required_pull_request_reviews-dismissal_restrictions): *(Optional `list(string)`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-dismissal_restrictions"></a>
706+
707+
The list of actor Names/IDs with dismissal access.
708+
If not empty, `restrict_dismissals` is ignored
709+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
710+
711+
Default is `[]`.
712+
713+
- [**`pull_request_bypassers`**](#attr-branch_protections_v4-required_pull_request_reviews-pull_request_bypassers): *(Optional `list(string)`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-pull_request_bypassers"></a>
714+
715+
The list of actor Names/IDs that are allowed to bypass pull request requirements.
716+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
717+
718+
Default is `[]`.
719+
720+
- [**`require_code_owner_reviews`**](#attr-branch_protections_v4-required_pull_request_reviews-require_code_owner_reviews): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-require_code_owner_reviews"></a>
721+
722+
Require an approved review in pull requests including files with a designated code owner.
723+
724+
Default is `true`.
725+
726+
- [**`required_approving_review_count`**](#attr-branch_protections_v4-required_pull_request_reviews-required_approving_review_count): *(Optional `number`)*<a name="attr-branch_protections_v4-required_pull_request_reviews-required_approving_review_count"></a>
727+
728+
Require x number of approvals to satisfy branch protection requirements.
729+
If this is specified it must be a number between 0-6.
730+
731+
Default is `0`.
732+
733+
- [**`required_status_checks`**](#attr-branch_protections_v4-required_status_checks): *(Optional `object(required_status_checks)`)*<a name="attr-branch_protections_v4-required_status_checks"></a>
734+
735+
Enforce restrictions for required status checks.
736+
See Required Status Checks below for details.
737+
738+
The `required_status_checks` object accepts the following attributes:
739+
740+
- [**`strict`**](#attr-branch_protections_v4-required_status_checks-strict): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_status_checks-strict"></a>
741+
742+
Require branches to be up to date before merging.
743+
744+
Default is `false`.
745+
746+
- [**`contexts`**](#attr-branch_protections_v4-required_status_checks-contexts): *(Optional `list(string)`)*<a name="attr-branch_protections_v4-required_status_checks-contexts"></a>
747+
748+
The list of status checks to require in order to merge into this branch. If default is `[]` no status checks are required.
749+
750+
Default is `[]`.
751+
655752
#### Issue Labels Configuration
656753

657754
- [**`issue_labels`**](#var-issue_labels): *(Optional `list(issue_label)`)*<a name="var-issue_labels"></a>

0 commit comments

Comments
 (0)