Skip to content

Commit 31c2492

Browse files
committed
refactor!: allow computed values in v4 branch protections
1 parent 00556eb commit 31c2492

File tree

5 files changed

+112
-100
lines changed

5 files changed

+112
-100
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.

README.md

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -646,53 +646,55 @@ This is due to some terraform limitation and we will update the module once terr
646646

647647
Default is `[]`.
648648

649-
- [**`branch_protections`**](#var-branch_protections): *(Optional `list(branch_protection_v3)`)*<a name="var-branch_protections"></a>
650-
651-
**_DEPRECATED_** To ensure compatibility with future versions of this module, please use `branch_protections_v3`.
652-
This argument is ignored if `branch_protections_v3` is used. Please see `branch_protections_v3` for supported attributes.
653-
654-
Default is `[]`.
655-
656649
#### Branch Protections v4 Configuration
657650

658-
- [**`branch_protections_v4`**](#var-branch_protections_v4): *(Optional `map(branch_protection_v4)`)*<a name="var-branch_protections_v4"></a>
651+
- [**`branch_protections_v4`**](#var-branch_protections_v4): *(Optional `list(branch_protection_v4)`)*<a name="var-branch_protections_v4"></a>
659652

660-
This map allows you to configure v4 branch protection for repositories in your organization.
653+
This resource allows you to configure v4 branch protection for repositories in your organization.
661654

662-
Each element in the map is a branch to be protected and the value the corresponding to the desired configuration for the branch.
655+
Each element in the list is a branch to be protected and the value the corresponding to the desired configuration for the branch.
663656

664657
When applied, the branch will be protected from forced pushes and deletion.
665658
Additional constraints, such as required status checks or restrictions on users and teams, can also be configured.
666659

667-
**_NOTE_** This will take precedence over v3 branch protections.
660+
**_NOTE:_** May conflict with v3 branch protections if used for the same branch.
661+
662+
Default is `[]`.
663+
664+
Each `branch_protection_v4` object in the list accepts the following attributes:
665+
666+
- [**`pattern`**](#attr-branch_protections_v4-pattern): *(**Required** `string`)*<a name="attr-branch_protections_v4-pattern"></a>
667+
668+
Identifies the protection rule pattern.
668669

669-
Default is `null`.
670+
- [**`_key`**](#attr-branch_protections_v4-_key): *(Optional `string`)*<a name="attr-branch_protections_v4-_key"></a>
670671

671-
Each `branch_protection_v4` object in the map accepts the following attributes:
672+
An alternative key to use in `for_each` resource creation.
673+
Defaults to the value of `var.pattern`.
672674

673675
- [**`allows_deletions`**](#attr-branch_protections_v4-allows_deletions): *(Optional `bool`)*<a name="attr-branch_protections_v4-allows_deletions"></a>
674676

675-
Setting this to true to allow the branch to be deleted.
677+
Setting this to `true` to allow the branch to be deleted.
676678

677679
Default is `false`.
678680

679681
- [**`allows_force_pushes`**](#attr-branch_protections_v4-allows_force_pushes): *(Optional `bool`)*<a name="attr-branch_protections_v4-allows_force_pushes"></a>
680682

681-
Setting this to true to allow force pushes on the branch.
683+
Setting this to `true` to allow force pushes on the branch.
682684

683685
Default is `false`.
684686

685687
- [**`blocks_creations`**](#attr-branch_protections_v4-blocks_creations): *(Optional `bool`)*<a name="attr-branch_protections_v4-blocks_creations"></a>
686688

687-
Setting this to true will block creating the branch.
689+
Setting this to `true` will block creating the branch.
688690

689691
Default is `false`.
690692

691693
- [**`enforce_admins`**](#attr-branch_protections_v4-enforce_admins): *(Optional `bool`)*<a name="attr-branch_protections_v4-enforce_admins"></a>
692694

693-
Setting this to true enforces status checks for repository administrators.
695+
Keeping this as `true` enforces status checks for repository administrators.
694696

695-
Default is `false`.
697+
Default is `true`.
696698

697699
- [**`push_restrictions`**](#attr-branch_protections_v4-push_restrictions): *(Optional `list(string)`)*<a name="attr-branch_protections_v4-push_restrictions"></a>
698700

@@ -723,8 +725,6 @@ This is due to some terraform limitation and we will update the module once terr
723725

724726
Enforce restrictions for pull request reviews.
725727

726-
Default is `null`.
727-
728728
The `required_pull_request_reviews` object accepts the following attributes:
729729

730730
- [**`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>
@@ -733,26 +733,30 @@ This is due to some terraform limitation and we will update the module once terr
733733

734734
Default is `true`.
735735

736+
- [**`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>
737+
738+
Restrict pull request review dismissals.
739+
736740
- [**`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>
737741

738742
The list of actor Names/IDs with dismissal access.
739-
If not empty, restrict_dismissals is ignored.
740-
Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
743+
If not empty, `restrict_dismissals` is ignored
744+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
741745

742746
Default is `[]`.
743747

744748
- [**`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>
745749

746750
The list of actor Names/IDs that are allowed to bypass pull request requirements.
747-
Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
751+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
748752

749753
Default is `[]`.
750754

751755
- [**`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>
752756

753757
Require an approved review in pull requests including files with a designated code owner.
754758

755-
Default is `false`.
759+
Default is `true`.
756760

757761
- [**`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>
758762

@@ -766,8 +770,6 @@ This is due to some terraform limitation and we will update the module once terr
766770
Enforce restrictions for required status checks.
767771
See Required Status Checks below for details.
768772

769-
Default is `null`.
770-
771773
The `required_status_checks` object accepts the following attributes:
772774

773775
- [**`strict`**](#attr-branch_protections_v4-required_status_checks-strict): *(Optional `bool`)*<a name="attr-branch_protections_v4-required_status_checks-strict"></a>

README.tfdoc.hcl

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -821,63 +821,70 @@ section {
821821
}
822822
}
823823
}
824-
825-
variable "branch_protections" {
826-
type = list(branch_protection_v3)
827-
default = []
828-
description = <<-END
829-
**_DEPRECATED_** To ensure compatibility with future versions of this module, please use `branch_protections_v3`.
830-
This argument is ignored if `branch_protections_v3` is used. Please see `branch_protections_v3` for supported attributes.
831-
END
832-
}
833824
}
834825

835826
section {
836827
title = "Branch Protections v4 Configuration"
837828

838829
variable "branch_protections_v4" {
839-
type = map(branch_protection_v4)
840-
default = null
830+
type = list(branch_protection_v4)
831+
default = []
841832
description = <<-END
842-
This map allows you to configure v4 branch protection for repositories in your organization.
833+
This resource allows you to configure v4 branch protection for repositories in your organization.
843834
844-
Each element in the map is a branch to be protected and the value the corresponding to the desired configuration for the branch.
835+
Each element in the list is a branch to be protected and the value the corresponding to the desired configuration for the branch.
845836
846837
When applied, the branch will be protected from forced pushes and deletion.
847838
Additional constraints, such as required status checks or restrictions on users and teams, can also be configured.
848839
849-
**_NOTE_** This will take precedence over v3 branch protections.
840+
**_NOTE:_** May conflict with v3 branch protections if used for the same branch.
850841
END
851842

843+
attribute "pattern" {
844+
type = string
845+
required = true
846+
description = <<-END
847+
Identifies the protection rule pattern.
848+
END
849+
}
850+
851+
attribute "_key" {
852+
type = string
853+
description = <<-END
854+
An alternative key to use in `for_each` resource creation.
855+
Defaults to the value of `var.pattern`.
856+
END
857+
}
858+
852859
attribute "allows_deletions" {
853860
type = bool
854861
default = false
855862
description = <<-END
856-
Setting this to true to allow the branch to be deleted.
863+
Setting this to `true` to allow the branch to be deleted.
857864
END
858865
}
859866

860867
attribute "allows_force_pushes" {
861868
type = bool
862869
default = false
863870
description = <<-END
864-
Setting this to true to allow force pushes on the branch.
871+
Setting this to `true` to allow force pushes on the branch.
865872
END
866873
}
867874

868875
attribute "blocks_creations" {
869876
type = bool
870877
default = false
871878
description = <<-END
872-
Setting this to true will block creating the branch.
879+
Setting this to `true` will block creating the branch.
873880
END
874881
}
875882

876883
attribute "enforce_admins" {
877884
type = bool
878-
default = false
885+
default = true
879886
description = <<-END
880-
Setting this to true enforces status checks for repository administrators.
887+
Keeping this as `true` enforces status checks for repository administrators.
881888
END
882889
}
883890

@@ -916,7 +923,6 @@ section {
916923

917924
attribute "required_pull_request_reviews" {
918925
type = object(required_pull_request_reviews)
919-
default = null
920926
description = <<-END
921927
Enforce restrictions for pull request reviews.
922928
END
@@ -929,13 +935,20 @@ section {
929935
END
930936
}
931937

938+
attribute "restrict_dismissals" {
939+
type = bool
940+
description = <<-END
941+
Restrict pull request review dismissals.
942+
END
943+
}
944+
932945
attribute "dismissal_restrictions" {
933946
type = list(string)
934947
default = []
935948
description = <<-END
936949
The list of actor Names/IDs with dismissal access.
937-
If not empty, restrict_dismissals is ignored.
938-
Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
950+
If not empty, `restrict_dismissals` is ignored
951+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
939952
END
940953
}
941954

@@ -944,13 +957,13 @@ section {
944957
default = []
945958
description = <<-END
946959
The list of actor Names/IDs that are allowed to bypass pull request requirements.
947-
Actor names must either begin with a "/" for users or the organization name followed by a "/" for teams.
960+
Actor names must either begin with a `/` for users or the organization name followed by a `/` for teams.
948961
END
949962
}
950963

951964
attribute "require_code_owner_reviews" {
952965
type = bool
953-
default = false
966+
default = true
954967
description = <<-END
955968
Require an approved review in pull requests including files with a designated code owner.
956969
END
@@ -968,7 +981,6 @@ section {
968981

969982
attribute "required_status_checks" {
970983
type = object(required_status_checks)
971-
default = null
972984
description = <<-END
973985
Enforce restrictions for required status checks.
974986
See Required Status Checks below for details.

0 commit comments

Comments
 (0)