Skip to content

Commit b651ff5

Browse files
committed
fix: omit default values in generated group resources
1 parent 52b01ec commit b651ff5

3 files changed

Lines changed: 31 additions & 18 deletions

File tree

internal/terraform/groups.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ func WriteGroups(groups []*gl.Group, w io.Writer, groupRefs groupRefMap) error {
2525
if g.Description != "" {
2626
body.SetAttributeValue("description", cty.StringVal(g.Description))
2727
}
28-
if g.Visibility != "" {
28+
if g.Visibility != gl.PublicVisibility {
2929
body.SetAttributeValue("visibility_level", cty.StringVal(string(g.Visibility)))
3030
}
3131
if g.ParentID != 0 {
3232
setGroupIDAttribute(body, "parent_id", g.ParentID, groupRefs)
3333
}
34-
if g.LFSEnabled {
34+
if !g.LFSEnabled {
3535
body.SetAttributeValue("lfs_enabled", cty.BoolVal(g.LFSEnabled))
3636
}
37-
if g.RequestAccessEnabled {
37+
if !g.RequestAccessEnabled {
3838
body.SetAttributeValue("request_access_enabled", cty.BoolVal(g.RequestAccessEnabled))
3939
}
4040
if g.MembershipLock {
@@ -46,13 +46,13 @@ func WriteGroups(groups []*gl.Group, w io.Writer, groupRefs groupRefMap) error {
4646
if g.RequireTwoFactorAuth {
4747
body.SetAttributeValue("require_two_factor_authentication", cty.BoolVal(g.RequireTwoFactorAuth))
4848
}
49-
if g.TwoFactorGracePeriod != 0 {
49+
if g.TwoFactorGracePeriod != 48 {
5050
body.SetAttributeValue("two_factor_grace_period", cty.NumberIntVal(g.TwoFactorGracePeriod))
5151
}
52-
if g.ProjectCreationLevel != "" {
52+
if g.ProjectCreationLevel != gl.DeveloperProjectCreation {
5353
body.SetAttributeValue("project_creation_level", cty.StringVal(string(g.ProjectCreationLevel)))
5454
}
55-
if g.SubGroupCreationLevel != "" {
55+
if g.SubGroupCreationLevel != gl.MaintainerSubGroupCreationLevelValue {
5656
body.SetAttributeValue("subgroup_creation_level", cty.StringVal(string(g.SubGroupCreationLevel)))
5757
}
5858
if g.AutoDevopsEnabled {
@@ -67,13 +67,13 @@ func WriteGroups(groups []*gl.Group, w io.Writer, groupRefs groupRefMap) error {
6767
if g.PreventForkingOutsideGroup {
6868
body.SetAttributeValue("prevent_forking_outside_group", cty.BoolVal(g.PreventForkingOutsideGroup))
6969
}
70-
if g.SharedRunnersSetting != "" {
70+
if g.SharedRunnersSetting != gl.EnabledSharedRunnersSettingValue {
7171
body.SetAttributeValue("shared_runners_setting", cty.StringVal(string(g.SharedRunnersSetting)))
7272
}
7373
if g.DefaultBranch != "" {
7474
body.SetAttributeValue("default_branch", cty.StringVal(g.DefaultBranch))
7575
}
76-
if g.WikiAccessLevel != "" {
76+
if g.WikiAccessLevel != gl.EnabledAccessControl {
7777
body.SetAttributeValue("wiki_access_level", cty.StringVal(string(g.WikiAccessLevel)))
7878
}
7979
if g.IPRestrictionRanges != "" {

internal/terraform/groups_test.go

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@ import (
1111
func TestWriteGroupsDefaultsOmitted(t *testing.T) {
1212
groups := []*gl.Group{
1313
{
14-
Name: "My Group",
15-
Path: "my-group",
16-
EmailsEnabled: true,
14+
Name: "My Group",
15+
Path: "my-group",
16+
Visibility: gl.PublicVisibility,
17+
LFSEnabled: true,
18+
RequestAccessEnabled: true,
19+
TwoFactorGracePeriod: 48,
20+
ProjectCreationLevel: gl.DeveloperProjectCreation,
21+
SubGroupCreationLevel: gl.MaintainerSubGroupCreationLevelValue,
22+
SharedRunnersSetting: gl.EnabledSharedRunnersSettingValue,
23+
WikiAccessLevel: gl.EnabledAccessControl,
24+
EmailsEnabled: true,
1725
},
1826
}
1927

@@ -29,10 +37,18 @@ func TestWriteGroupsAllOptions(t *testing.T) {
2937
level := gl.MaintainerPermissions
3038
groups := []*gl.Group{
3139
{
32-
ID: 42,
33-
Name: "Parent Group",
34-
Path: "parent-group",
35-
EmailsEnabled: true,
40+
ID: 42,
41+
Name: "Parent Group",
42+
Path: "parent-group",
43+
Visibility: gl.PublicVisibility,
44+
LFSEnabled: true,
45+
RequestAccessEnabled: true,
46+
TwoFactorGracePeriod: 48,
47+
ProjectCreationLevel: gl.DeveloperProjectCreation,
48+
SubGroupCreationLevel: gl.MaintainerSubGroupCreationLevelValue,
49+
SharedRunnersSetting: gl.EnabledSharedRunnersSettingValue,
50+
WikiAccessLevel: gl.EnabledAccessControl,
51+
EmailsEnabled: true,
3652
},
3753
{
3854
ID: 100,

internal/terraform/testdata/groups_full.tf

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,11 @@ resource "gitlab_group" "full_group" {
99
description = "Full group description"
1010
visibility_level = "private"
1111
parent_id = gitlab_group.parent_group.id
12-
lfs_enabled = true
13-
request_access_enabled = true
1412
membership_lock = true
1513
share_with_group_lock = true
1614
require_two_factor_authentication = true
1715
two_factor_grace_period = 7
1816
project_creation_level = "owner"
19-
subgroup_creation_level = "maintainer"
2017
auto_devops_enabled = true
2118
emails_enabled = false
2219
mentions_disabled = true

0 commit comments

Comments
 (0)