Send gitlab_group push rules set to false, 0 or an empty string on creation
What does this MR do and why?
When a group has no push rule yet, gitlab_group creates one with POST /groups/:id/push_rule, and expandAddGroupPushRuleOptions builds that request with d.GetOk, which reports false, 0 and "" as not set. An attribute set to one of those values in push_rules was therefore never sent, and a block holding nothing else sent no request at all. GitLab then has no push rule for the group, the next read stores an empty push_rules, and every plan proposes adding the block again, which is what the issue and the second report in it describe.
This MR decides whether an attribute is set from the raw configuration, where an attribute the block leaves out is null, the way gitlab_project already does for the booleans of its push_rules. The value still comes from d.Get. Updating a push rule that already exists is unchanged: that path uses HasChange and already sends false.
Two things to be aware of:
- A
push_rules {}block that sets no attribute still creates nothing, because the API requires at least one attribute. - On GitLab CE, which has no group push rules, a block holding only such values now fails with
Group push rules are not supported in your version of GitLab, as any otherpush_rulesblock already does there. Before, it applied without an error and changed nothing.
The tests are a new TestAccGitlabGroup_pushRulesZeroValuesEE, which creates groups whose push rules hold only such values and adds one to a group that had none, and a step in TestAccGitlabGroup_basicPushRulesCE that adds a block set to false only.
Closes #6832
How to verify
unset GITLAB_TOKEN && make testacc RUN=TestAccGitlabGroup_The acceptance tests run once against a licensed SERVICE=gitlab-ee make testacc-up instance, since group push rules are a paid feature, and once against a CE one for TestAccGitlabGroup_basicPushRulesCE. With the resource as it is on main, TestAccGitlabGroup_pushRulesZeroValuesEE fails on its first step because the group has no push rule, and the new CE step expects an error and gets none.
What I ran (GitLab EE 19.4.1 with an Ultimate license, GitLab CE 19.4.1, Go 1.26.5)
TestAccGitlabGroup_pushRulesZeroValuesEE on EE with the resource as it is on main:
Step 1/4 error: Check failed: Check 1/2 error: 404 Not FoundThe same first step with its checks taken out, so that the framework's plan check after the apply runs:
Step 1/4 error: After applying this test step, the plan was not empty.
# gitlab_group.false_value will be updated in-place
~ resource "gitlab_group" "false_value" {
+ push_rules {
+ reject_unsigned_commits = false
}
}
# gitlab_group.zero_values will be updated in-place
~ resource "gitlab_group" "zero_values" {
+ push_rules {
+ commit_committer_check = false
+ commit_committer_name_check = false
+ deny_delete_tag = false
+ max_file_size = 0
+ member_check = false
+ prevent_secrets = false
+ reject_non_dco_commits = false
+ reject_unsigned_commits = false
# (5 unchanged attributes hidden)
}
}
Plan: 0 to add, 2 to change, 0 to destroy.TestAccGitlabGroup_basicPushRulesCE on CE with the resource as it is on main:
Step 3/4, expected an error but got noneThis branch, make testacc RUN=TestAccGitlabGroup_ on EE: 27 passed, and TestAccGitlabGroup_basicPushRulesCE skipped. On CE: 22 passed, and the 6 EE-only tests skipped.
make reviewable finishes cleanly and changes no tracked file, and make lint-golangci (0 issues), lint-tfprovider, lint-examples-tf, lint-examples-sh and lint-custom pass.