Skip to content

Commit 62e7313

Browse files
committed
resource/gitlab_group: Fix passing false to API for explicitly set optional attributes
Closes: #1154
1 parent 4b20f8c commit 62e7313

File tree

2 files changed

+45
-5
lines changed

2 files changed

+45
-5
lines changed

internal/provider/resource_gitlab_group.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ func resourceGitlabGroupCreate(ctx context.Context, d *schema.ResourceData, meta
183183
options.ShareWithGroupLock = gitlab.Bool(v.(bool))
184184
}
185185

186-
if v, ok := d.GetOk("require_two_factor_authentication"); ok {
186+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
187+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
188+
if v, ok := d.GetOkExists("require_two_factor_authentication"); ok {
187189
options.RequireTwoFactorAuth = gitlab.Bool(v.(bool))
188190
}
189191

@@ -195,19 +197,25 @@ func resourceGitlabGroupCreate(ctx context.Context, d *schema.ResourceData, meta
195197
options.ProjectCreationLevel = stringToProjectCreationLevel(v.(string))
196198
}
197199

198-
if v, ok := d.GetOk("auto_devops_enabled"); ok {
200+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
201+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
202+
if v, ok := d.GetOkExists("auto_devops_enabled"); ok {
199203
options.AutoDevopsEnabled = gitlab.Bool(v.(bool))
200204
}
201205

202206
if v, ok := d.GetOk("subgroup_creation_level"); ok {
203207
options.SubGroupCreationLevel = stringToSubGroupCreationLevel(v.(string))
204208
}
205209

206-
if v, ok := d.GetOk("emails_disabled"); ok {
210+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
211+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
212+
if v, ok := d.GetOkExists("emails_disabled"); ok {
207213
options.EmailsDisabled = gitlab.Bool(v.(bool))
208214
}
209215

210-
if v, ok := d.GetOk("mentions_disabled"); ok {
216+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
217+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
218+
if v, ok := d.GetOkExists("mentions_disabled"); ok {
211219
options.MentionsDisabled = gitlab.Bool(v.(bool))
212220
}
213221

@@ -232,7 +240,9 @@ func resourceGitlabGroupCreate(ctx context.Context, d *schema.ResourceData, meta
232240

233241
var updateOptions gitlab.UpdateGroupOptions
234242

235-
if v, ok := d.GetOk("prevent_forking_outside_group"); ok {
243+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
244+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
245+
if v, ok := d.GetOkExists("prevent_forking_outside_group"); ok {
236246
updateOptions.PreventForkingOutsideGroup = gitlab.Bool(v.(bool))
237247
}
238248

internal/provider/resource_gitlab_group_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,36 @@ func testAccCheckGitlabGroupDisappears(group *gitlab.Group) resource.TestCheckFu
313313
}
314314
}
315315

316+
func TestAccGitlabGroup_SetDefaultFalseBooleansOnCreate(t *testing.T) {
317+
rInt := acctest.RandInt()
318+
319+
resource.ParallelTest(t, resource.TestCase{
320+
ProviderFactories: providerFactories,
321+
CheckDestroy: testAccCheckGitlabProjectDestroy,
322+
Steps: []resource.TestStep{
323+
{
324+
Config: fmt.Sprintf(`
325+
resource "gitlab_group" "this" {
326+
name = "foo-%d"
327+
path = "path-%d"
328+
visibility_level = "public"
329+
330+
require_two_factor_authentication = false
331+
auto_devops_enabled = false
332+
emails_disabled = false
333+
mentions_disabled = false
334+
prevent_forking_outside_group = false
335+
}`, rInt, rInt),
336+
},
337+
{
338+
ResourceName: "gitlab_group.this",
339+
ImportState: true,
340+
ImportStateVerify: true,
341+
},
342+
},
343+
})
344+
}
345+
316346
func testAccCheckGitlabGroupExists(n string, group *gitlab.Group) resource.TestCheckFunc {
317347
return func(s *terraform.State) error {
318348
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)