Skip to content

Commit 087f021

Browse files
committed
Support setting group default_branch_protection to 0.
1 parent 8d4cf46 commit 087f021

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

internal/provider/resource_gitlab_group.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,9 @@ func resourceGitlabGroupCreate(ctx context.Context, d *schema.ResourceData, meta
208208
options.ParentID = gitlab.Int(v.(int))
209209
}
210210

211-
if v, ok := d.GetOk("default_branch_protection"); ok {
211+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
212+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
213+
if v, ok := d.GetOkExists("default_branch_protection"); ok {
212214
options.DefaultBranchProtection = gitlab.Int(v.(int))
213215
}
214216

internal/provider/resource_gitlab_group_test.go

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func TestAccGitlabGroup_basic(t *testing.T) {
4141
},
4242
// Update the group to change the description
4343
{
44-
Config: testAccGitlabGroupUpdateConfig(rInt),
44+
Config: testAccGitlabGroupUpdateConfig(rInt, 1),
4545
Check: resource.ComposeTestCheckFunc(
4646
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
4747
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
@@ -63,6 +63,30 @@ func TestAccGitlabGroup_basic(t *testing.T) {
6363
}),
6464
),
6565
},
66+
// Update the group to use zero-value `default_branch_protection`
67+
{
68+
Config: testAccGitlabGroupUpdateConfig(rInt, 0),
69+
Check: resource.ComposeTestCheckFunc(
70+
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
71+
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
72+
Name: fmt.Sprintf("bar-name-%d", rInt),
73+
Path: fmt.Sprintf("bar-path-%d", rInt),
74+
Description: "Terraform acceptance tests! Updated description",
75+
LFSEnabled: false,
76+
Visibility: "public", // default value
77+
RequestAccessEnabled: true,
78+
ProjectCreationLevel: "developer",
79+
SubGroupCreationLevel: "maintainer",
80+
RequireTwoFactorAuth: true,
81+
TwoFactorGracePeriod: 56,
82+
AutoDevopsEnabled: true,
83+
EmailsDisabled: true,
84+
MentionsDisabled: true,
85+
ShareWithGroupLock: true,
86+
DefaultBranchProtection: 0,
87+
}),
88+
),
89+
},
6690
// Update the group to put the name and description back
6791
{
6892
Config: testAccGitlabGroupConfig(rInt),
@@ -398,7 +422,7 @@ resource "gitlab_group" "foo" {
398422
`, rInt, rInt)
399423
}
400424

401-
func testAccGitlabGroupUpdateConfig(rInt int) string {
425+
func testAccGitlabGroupUpdateConfig(rInt int, defaultBranchProtection int) string {
402426
return fmt.Sprintf(`
403427
resource "gitlab_group" "foo" {
404428
name = "bar-name-%d"
@@ -414,13 +438,13 @@ resource "gitlab_group" "foo" {
414438
emails_disabled = true
415439
mentions_disabled = true
416440
share_with_group_lock = true
417-
default_branch_protection = 1
441+
default_branch_protection = %d
418442
419443
# So that acceptance tests can be run in a gitlab organization
420444
# with no billing
421445
visibility_level = "public"
422446
}
423-
`, rInt, rInt)
447+
`, rInt, rInt, defaultBranchProtection)
424448
}
425449

426450
func testAccGitlabNestedGroupConfig(rInt int) string {

0 commit comments

Comments
 (0)