MR approvals API ignores fields
Bug Report
From @sean_carroll in #1355 (comment 1325251954):
There is an issue with the POST /api/v4/projects/REDACTED/approvals
endpoint.
When the disable_overriding_approvers_per_merge_request
and merge_requests_disable_committers_approval
flags are set to false
, the response doesn't contain any errors, but returns both fields as still being true
. So it seems like the API is just ignoring those fields in that case.
The API should consider the value of the disable_overriding_approvers_per_merge_request
and merge_requests_disable_committers_approval
flags.
Added by @timofurrer: it turned out that the problem here is the underlying projects MR approval API which ignores certain fields.
In #1355 (comment 1245973197) there are more details. And further below is the output of the relevant API call (req/resp).
Original provider related report:
The gitlab_project_level_mr_approvals Terraform resource is used to configure merge request approval rules at the project level in GitLab. However, after successfully provisioning a GitLab project using this resource, the Terraform state still shows that changes will be made, even though the provisioning was successful and the project has the desired approval rules configured.
This can be confusing and can lead to unnecessary re-provisioning of the project, which can cause issues and waste time and resources.
It would be helpful if the Terraform state was updated correctly to reflect the actual state of the GitLab project after successful provisioning, so that users can easily see the current configuration and avoid unnecessary re-provisioning.
Relevant Terraform Configuration
resource "gitlab_project_level_mr_approvals" "mr_approvals_test" {
for_each = toset(local.test_names)
project_id = gitlab_project.test[each.key].id
reset_approvals_on_push = true
disable_overriding_approvers_per_merge_request = false
merge_requests_author_approval = false
merge_requests_disable_committers_approval = false
}
Relevant Log Output
Terraform plan
output after a successful terraform apply
:
data.gitlab_group.test: Reading..
gitlab_group.test: Refreshing state... [id=xxx]
data.gitlab_group.test: Read complete after 2s [id-xxx] data.gitlab_projects.test name: Reading..
gitlab_project.test["test"]: Refreshing state. .. [id-yyy]
gitlab_project_level_mr_approvals.mr_approvals_test["test"):Refreshing state... [id-yyy]
gitlab_branch_protection.master_branch_protection_test["test"]: Refreshing state... [id-xxx:redacted)
data.gitlab_projects.test_name: Read complete after 2s [id-aaa-bbbbbb]
Terraform used the selected providers to generate the following execution plan. Resource actions are indicated with the following symbols:
~ update in-place
Terraform will perform the following actions:
# gitlab_project_level_mr_approvals.mr_approvals_test["test"] will be updated in-place
~ resource "gitlab_project_level _mr_approvals" "mr_approvals_test" {
~ disable_overriding_approvers_per_merge_request = true -> false
id = ccc
~ merge_requests_disable_committers_approval = true -> false
# (4 unchanged attributes hidden)
}
Plan: 0 to add, 1 to change, 0 to destroy.
Relevant API call
See #1355 (comment 1245973197) for the complete conversation.
==> POST /api/v4/projects/REDACTED/approvals
TRANS-ID: 93838e36-9761-e7db-1191-d61af0203e8a at 2023-01-06T13:11:41.451647+01:00
HTTP BODY:
{
"disable_overriding_approvers_per_merge_request": false,
"merge_requests_disable_committers_approval": false
}
<== 201 Created
TRANS-ID: 93838e36-9761-e7db-1191-d61af0203e8a at 2023-01-06T13:11:41.908371+01:00
HTTP BODY:
{
"approvers": [],
"approver_groups": [],
"approvals_before_merge": 1,
"reset_approvals_on_push": true,
"selective_code_owner_removals": false,
"disable_overriding_approvers_per_merge_request": true,
"merge_requests_author_approval": false,
"merge_requests_disable_committers_approval": true,
"require_password_to_approve": false
}
Additional Details
- GitLab Terraform Provider Version:
v3.18.0
- GitLab Version:
GitLab Enterprise Edition 15.7.0-pre 952324ffaf6
- Terraform Version:
v1.3.1