gitlab_project_approval_rule is missing parameter 'applies_to_all_protected_branches'
Bug Report
Currently all branch ids have to be explicitly listed, i would like to instead apply the rule to all current and future protected branches via 'applies_to_all_protected_branches'.
The API supports it: https://docs.gitlab.com/ee/api/merge_request_approvals.html#create-project-level-rule
But it is missing in terraform
Relevant Terraform Configuration
# possible
resource "gitlab_project_approval_rule" "example-two" {
project = 5
name = "Example Rule 2"
approvals_required = 3
user_ids = [50, 500]
group_ids = [51]
protected_branch_ids = [gitlab_branch_protection.example.branch_protection_id]
}
# but i would like to do this
resource "gitlab_project_approval_rule" "example-two" {
project = 5
name = "Example Rule 2"
approvals_required = 3
user_ids = [50, 500]
group_ids = [51]
applies_to_all_protected_branches = true
}
Implementation Details
Implementing this will require adding a new applies_to_all_protected_branches
attribute to the schema for the gitlab_project_approval_rule
resource, which is located here. While the API will accept both protected_branch_ids
and applies_to_all_protected_branches
, it will ignore protected_branch_ids
if both are passed in, so the implementation in terraform should use ConflictsWith
to prevent both attributes being passed in together.
Within the Create
and Update
methods, the attribute should be set into the Rule Options object (go-gitlab already supports this attribute). Within the Read
method, the value should be ready from the response and set into the state file.
After that, one new test should be written confirming the ConflictsWith
value works properly and returns an error if both attributes are populated, and one new test step in the basic
test should be added ensuring the new attribute populates properly.
Additional Details
- GitLab Terraform Provider Version: v16.3.0
- GitLab Version: 16.3