Skip to content

Commit 4b20f8c

Browse files
committed
resource/gitlab_project: Fix passing false to API for explicitly set optional attributes
Closes: #1151
1 parent 5b3eaef commit 4b20f8c

File tree

2 files changed

+68
-13
lines changed

2 files changed

+68
-13
lines changed

internal/provider/resource_gitlab_project.go

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
812812
options.TagList = stringSetToStringSlice(v.(*schema.Set))
813813
}
814814

815-
if v, ok := d.GetOk("initialize_with_readme"); ok {
815+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
816+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
817+
if v, ok := d.GetOkExists("initialize_with_readme"); ok {
816818
options.InitializeWithReadme = gitlab.Bool(v.(bool))
817819
}
818820

@@ -828,7 +830,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
828830
options.TemplateProjectID = gitlab.Int(v.(int))
829831
}
830832

831-
if v, ok := d.GetOk("use_custom_template"); ok {
833+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
834+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
835+
if v, ok := d.GetOkExists("use_custom_template"); ok {
832836
options.UseCustomTemplate = gitlab.Bool(v.(bool))
833837
}
834838

@@ -844,7 +848,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
844848
options.CIConfigPath = gitlab.String(v.(string))
845849
}
846850

847-
if v, ok := d.GetOk("resolve_outdated_diff_discussions"); ok {
851+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
852+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
853+
if v, ok := d.GetOkExists("resolve_outdated_diff_discussions"); ok {
848854
options.ResolveOutdatedDiffDiscussions = gitlab.Bool(v.(bool))
849855
}
850856

@@ -860,11 +866,15 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
860866
options.AutoDevopsDeployStrategy = gitlab.String(v.(string))
861867
}
862868

863-
if v, ok := d.GetOk("auto_devops_enabled"); ok {
869+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
870+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
871+
if v, ok := d.GetOkExists("auto_devops_enabled"); ok {
864872
options.AutoDevopsEnabled = gitlab.Bool(v.(bool))
865873
}
866874

867-
if v, ok := d.GetOk("autoclose_referenced_issues"); ok {
875+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
876+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
877+
if v, ok := d.GetOkExists("autoclose_referenced_issues"); ok {
868878
options.AutocloseReferencedIssues = gitlab.Bool(v.(bool))
869879
}
870880

@@ -888,7 +898,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
888898
options.ContainerRegistryAccessLevel = stringToAccessControlValue(v.(string))
889899
}
890900

891-
if v, ok := d.GetOk("emails_disabled"); ok {
901+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
902+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
903+
if v, ok := d.GetOkExists("emails_disabled"); ok {
892904
options.EmailsDisabled = gitlab.Bool(v.(bool))
893905
}
894906

@@ -912,7 +924,9 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
912924
options.OperationsAccessLevel = stringToAccessControlValue(v.(string))
913925
}
914926

915-
if v, ok := d.GetOk("public_builds"); ok {
927+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
928+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
929+
if v, ok := d.GetOkExists("public_builds"); ok {
916930
options.PublicBuilds = gitlab.Bool(v.(bool))
917931
}
918932

@@ -1120,12 +1134,16 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
11201134

11211135
var editProjectOptions gitlab.EditProjectOptions
11221136

1123-
if v, ok := d.GetOk("mirror_overwrites_diverged_branches"); ok {
1137+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
1138+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
1139+
if v, ok := d.GetOkExists("mirror_overwrites_diverged_branches"); ok {
11241140
editProjectOptions.MirrorOverwritesDivergedBranches = gitlab.Bool(v.(bool))
11251141
editProjectOptions.ImportURL = gitlab.String(d.Get("import_url").(string))
11261142
}
11271143

1128-
if v, ok := d.GetOk("only_mirror_protected_branches"); ok {
1144+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
1145+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
1146+
if v, ok := d.GetOkExists("only_mirror_protected_branches"); ok {
11291147
editProjectOptions.OnlyMirrorProtectedBranches = gitlab.Bool(v.(bool))
11301148
editProjectOptions.ImportURL = gitlab.String(d.Get("import_url").(string))
11311149
}
@@ -1138,11 +1156,15 @@ func resourceGitlabProjectCreate(ctx context.Context, d *schema.ResourceData, me
11381156
editProjectOptions.MergeRequestsTemplate = gitlab.String(v.(string))
11391157
}
11401158

1141-
if v, ok := d.GetOk("merge_pipelines_enabled"); ok {
1159+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
1160+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
1161+
if v, ok := d.GetOkExists("merge_pipelines_enabled"); ok {
11421162
editProjectOptions.MergePipelinesEnabled = gitlab.Bool(v.(bool))
11431163
}
11441164

1145-
if v, ok := d.GetOk("merge_trains_enabled"); ok {
1165+
// nolint:staticcheck // SA1019 ignore deprecated GetOkExists
1166+
// lintignore: XR001 // TODO: replace with alternative for GetOkExists
1167+
if v, ok := d.GetOkExists("merge_trains_enabled"); ok {
11461168
editProjectOptions.MergeTrainsEnabled = gitlab.Bool(v.(bool))
11471169
}
11481170

internal/provider/resource_gitlab_project_test.go

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1126,7 +1126,7 @@ func TestAccGitlabProject_ImportURLMirrored(t *testing.T) {
11261126
func TestAccGitlabProject_templateMutualExclusiveNameAndID(t *testing.T) {
11271127
rInt := acctest.RandInt()
11281128

1129-
resource.Test(t, resource.TestCase{
1129+
resource.ParallelTest(t, resource.TestCase{
11301130
ProviderFactories: providerFactories,
11311131
CheckDestroy: testAccCheckGitlabProjectDestroy,
11321132
Steps: []resource.TestStep{
@@ -1225,7 +1225,7 @@ func TestAccGitlabProject_DeprecatedBuildCoverageRegex(t *testing.T) {
12251225
var received gitlab.Project
12261226
rInt := acctest.RandInt()
12271227

1228-
resource.Test(t, resource.TestCase{
1228+
resource.ParallelTest(t, resource.TestCase{
12291229
ProviderFactories: providerFactories,
12301230
CheckDestroy: testAccCheckGitlabProjectDestroy,
12311231
Steps: []resource.TestStep{
@@ -1252,6 +1252,39 @@ func TestAccGitlabProject_DeprecatedBuildCoverageRegex(t *testing.T) {
12521252
})
12531253
}
12541254

1255+
func TestAccGitlabProject_SetDefaultFalseBooleansOnCreate(t *testing.T) {
1256+
rInt := acctest.RandInt()
1257+
1258+
resource.ParallelTest(t, resource.TestCase{
1259+
ProviderFactories: providerFactories,
1260+
CheckDestroy: testAccCheckGitlabProjectDestroy,
1261+
Steps: []resource.TestStep{
1262+
{
1263+
Config: fmt.Sprintf(`
1264+
resource "gitlab_project" "this" {
1265+
name = "foo-%d"
1266+
visibility_level = "public"
1267+
1268+
initialize_with_readme = false
1269+
resolve_outdated_diff_discussions = false
1270+
auto_devops_enabled = false
1271+
autoclose_referenced_issues = false
1272+
emails_disabled = false
1273+
public_builds = false
1274+
merge_pipelines_enabled = false
1275+
merge_trains_enabled = false
1276+
}`, rInt),
1277+
},
1278+
{
1279+
ResourceName: "gitlab_project.this",
1280+
ImportState: true,
1281+
ImportStateVerify: true,
1282+
ImportStateVerifyIgnore: []string{"initialize_with_readme"},
1283+
},
1284+
},
1285+
})
1286+
}
1287+
12551288
func testAccCheckGitlabProjectExists(n string, project *gitlab.Project) resource.TestCheckFunc {
12561289
return func(s *terraform.State) error {
12571290
var err error

0 commit comments

Comments
 (0)