Skip to content

Commit 01b429b

Browse files
More group options (#362)
* rebase * rebase * whitespace tweaks * more tweaks * update tests - default visibility is public * make fmt * set defaults * clear computed * defaults * default * more test fixes * more defaults * remove default on runner limits; set to Computed * tweak tests * fix make test failures * set default * explicit wants * explicit wants * fix test values * update test want values to defaults * shared runners not Compute * dropping runner minutes support in this PR * update docs * sync defaults * fix format * fix nested tests * maybe order matters? * Update website/docs/r/group.html.markdown Co-authored-by: Adam Snyder <[email protected]> * Update website/docs/r/group.html.markdown Co-authored-by: Adam Snyder <[email protected]> Co-authored-by: Adam Snyder <[email protected]>
1 parent 98a327c commit 01b429b

File tree

4 files changed

+288
-34
lines changed

4 files changed

+288
-34
lines changed

gitlab/resource_gitlab_group.go

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,51 @@ func resourceGitlabGroup() *schema.Resource {
6161
"visibility_level": {
6262
Type: schema.TypeString,
6363
Optional: true,
64-
Computed: true,
64+
Default: "private",
6565
ValidateFunc: validation.StringInSlice([]string{"private", "internal", "public"}, true),
6666
},
67+
"share_with_group_lock": {
68+
Type: schema.TypeBool,
69+
Optional: true,
70+
Default: false,
71+
},
72+
"project_creation_level": {
73+
Type: schema.TypeString,
74+
Optional: true,
75+
Default: "maintainer",
76+
ValidateFunc: validation.StringInSlice([]string{"noone", "maintainer", "developer"}, true),
77+
},
78+
"auto_devops_enabled": {
79+
Type: schema.TypeBool,
80+
Optional: true,
81+
Default: false,
82+
},
83+
"emails_disabled": {
84+
Type: schema.TypeBool,
85+
Optional: true,
86+
Default: false,
87+
},
88+
"mentions_disabled": {
89+
Type: schema.TypeBool,
90+
Optional: true,
91+
Default: false,
92+
},
93+
"subgroup_creation_level": {
94+
Type: schema.TypeString,
95+
Optional: true,
96+
Default: "owner",
97+
ValidateFunc: validation.StringInSlice([]string{"owner", "maintainer"}, true),
98+
},
99+
"require_two_factor_authentication": {
100+
Type: schema.TypeBool,
101+
Optional: true,
102+
Default: false,
103+
},
104+
"two_factor_grace_period": {
105+
Type: schema.TypeInt,
106+
Optional: true,
107+
Default: 48,
108+
},
67109
"parent_id": {
68110
Type: schema.TypeInt,
69111
Optional: true,
@@ -99,6 +141,38 @@ func resourceGitlabGroupCreate(d *schema.ResourceData, meta interface{}) error {
99141
options.Visibility = stringToVisibilityLevel(v.(string))
100142
}
101143

144+
if v, ok := d.GetOk("share_with_group_lock"); ok {
145+
options.ShareWithGroupLock = gitlab.Bool(v.(bool))
146+
}
147+
148+
if v, ok := d.GetOk("require_two_factor_authentication"); ok {
149+
options.RequireTwoFactorAuth = gitlab.Bool(v.(bool))
150+
}
151+
152+
if v, ok := d.GetOk("two_factor_grace_period"); ok {
153+
options.TwoFactorGracePeriod = gitlab.Int(v.(int))
154+
}
155+
156+
if v, ok := d.GetOk("project_creation_level"); ok {
157+
options.ProjectCreationLevel = stringToProjectCreationLevel(v.(string))
158+
}
159+
160+
if v, ok := d.GetOk("auto_devops_enabled"); ok {
161+
options.AutoDevopsEnabled = gitlab.Bool(v.(bool))
162+
}
163+
164+
if v, ok := d.GetOk("subgroup_creation_level"); ok {
165+
options.SubGroupCreationLevel = stringToSubGroupCreationLevel(v.(string))
166+
}
167+
168+
if v, ok := d.GetOk("emails_disabled"); ok {
169+
options.EmailsDisabled = gitlab.Bool(v.(bool))
170+
}
171+
172+
if v, ok := d.GetOk("mentions_disabled"); ok {
173+
options.MentionsDisabled = gitlab.Bool(v.(bool))
174+
}
175+
102176
if v, ok := d.GetOk("parent_id"); ok {
103177
options.ParentID = gitlab.Int(v.(int))
104178
}
@@ -144,8 +218,16 @@ func resourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
144218
d.Set("lfs_enabled", group.LFSEnabled)
145219
d.Set("request_access_enabled", group.RequestAccessEnabled)
146220
d.Set("visibility_level", group.Visibility)
221+
d.Set("project_creation_level", group.ProjectCreationLevel)
222+
d.Set("subgroup_creation_level", group.SubGroupCreationLevel)
223+
d.Set("require_two_factor_authentication", group.RequireTwoFactorAuth)
224+
d.Set("two_factor_grace_period", group.TwoFactorGracePeriod)
225+
d.Set("auto_devops_enabled", group.AutoDevopsEnabled)
226+
d.Set("emails_disabled", group.EmailsDisabled)
227+
d.Set("mentions_disabled", group.MentionsDisabled)
147228
d.Set("parent_id", group.ParentID)
148229
d.Set("runners_token", group.RunnersToken)
230+
d.Set("share_with_group_lock", group.ShareWithGroupLock)
149231

150232
return nil
151233
}
@@ -181,6 +263,38 @@ func resourceGitlabGroupUpdate(d *schema.ResourceData, meta interface{}) error {
181263
options.Visibility = stringToVisibilityLevel(v.(string))
182264
}
183265

266+
if d.HasChange("project_creation_level") {
267+
options.ProjectCreationLevel = stringToProjectCreationLevel(d.Get("project_creation_level").(string))
268+
}
269+
270+
if d.HasChange("subgroup_creation_level") {
271+
options.SubGroupCreationLevel = stringToSubGroupCreationLevel(d.Get("subgroup_creation_level").(string))
272+
}
273+
274+
if d.HasChange("require_two_factor_authentication") {
275+
options.RequireTwoFactorAuth = gitlab.Bool(d.Get("require_two_factor_authentication").(bool))
276+
}
277+
278+
if d.HasChange("two_factor_grace_period") {
279+
options.TwoFactorGracePeriod = gitlab.Int(d.Get("two_factor_grace_period").(int))
280+
}
281+
282+
if d.HasChange("auto_devops_enabled") {
283+
options.AutoDevopsEnabled = gitlab.Bool(d.Get("auto_devops_enabled").(bool))
284+
}
285+
286+
if d.HasChange("emails_disabled") {
287+
options.EmailsDisabled = gitlab.Bool(d.Get("emails_disabled").(bool))
288+
}
289+
290+
if d.HasChange("mentions_disabled") {
291+
options.MentionsDisabled = gitlab.Bool(d.Get("mentions_disabled").(bool))
292+
}
293+
294+
if d.HasChange("share_with_group_lock") {
295+
options.ShareWithGroupLock = gitlab.Bool(d.Get("share_with_group_lock").(bool))
296+
}
297+
184298
log.Printf("[DEBUG] update gitlab group %s", d.Id())
185299

186300
_, _, err := client.Groups.UpdateGroup(d.Id(), options)

gitlab/resource_gitlab_group_test.go

Lines changed: 120 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,14 @@ func TestAccGitlabGroup_basic(t *testing.T) {
2626
Check: resource.ComposeTestCheckFunc(
2727
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
2828
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
29-
Name: fmt.Sprintf("foo-name-%d", rInt),
30-
Path: fmt.Sprintf("foo-path-%d", rInt),
31-
Description: "Terraform acceptance tests",
32-
LFSEnabled: true,
29+
Name: fmt.Sprintf("foo-name-%d", rInt),
30+
Path: fmt.Sprintf("foo-path-%d", rInt),
31+
Description: "Terraform acceptance tests",
32+
LFSEnabled: true,
33+
Visibility: "public", // default value
34+
ProjectCreationLevel: "maintainer", // default value
35+
SubGroupCreationLevel: "owner", // default value
36+
TwoFactorGracePeriod: 48, // default value
3337
}),
3438
),
3539
},
@@ -39,23 +43,37 @@ func TestAccGitlabGroup_basic(t *testing.T) {
3943
Check: resource.ComposeTestCheckFunc(
4044
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
4145
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
42-
Name: fmt.Sprintf("bar-name-%d", rInt),
43-
Path: fmt.Sprintf("bar-path-%d", rInt),
44-
Description: "Terraform acceptance tests! Updated description",
45-
RequestAccessEnabled: true,
46+
Name: fmt.Sprintf("bar-name-%d", rInt),
47+
Path: fmt.Sprintf("bar-path-%d", rInt),
48+
Description: "Terraform acceptance tests! Updated description",
49+
LFSEnabled: false,
50+
Visibility: "public", // default value
51+
RequestAccessEnabled: true,
52+
ProjectCreationLevel: "developer",
53+
SubGroupCreationLevel: "maintainer",
54+
RequireTwoFactorAuth: true,
55+
TwoFactorGracePeriod: 56,
56+
AutoDevopsEnabled: true,
57+
EmailsDisabled: true,
58+
MentionsDisabled: true,
59+
ShareWithGroupLock: true,
4660
}),
4761
),
4862
},
49-
// Update the group to put the anem and description back
63+
// Update the group to put the name and description back
5064
{
5165
Config: testAccGitlabGroupConfig(rInt),
5266
Check: resource.ComposeTestCheckFunc(
5367
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
5468
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
55-
Name: fmt.Sprintf("foo-name-%d", rInt),
56-
Path: fmt.Sprintf("foo-path-%d", rInt),
57-
Description: "Terraform acceptance tests",
58-
LFSEnabled: true,
69+
Name: fmt.Sprintf("foo-name-%d", rInt),
70+
Path: fmt.Sprintf("foo-path-%d", rInt),
71+
Description: "Terraform acceptance tests",
72+
LFSEnabled: true,
73+
Visibility: "public", // default value
74+
ProjectCreationLevel: "maintainer", // default value
75+
SubGroupCreationLevel: "owner", // default value
76+
TwoFactorGracePeriod: 48, // default value
5977
}),
6078
),
6179
},
@@ -101,11 +119,15 @@ func TestAccGitlabGroup_nested(t *testing.T) {
101119
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
102120
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
103121
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
104-
Name: fmt.Sprintf("nfoo-name-%d", rInt),
105-
Path: fmt.Sprintf("nfoo-path-%d", rInt),
106-
Description: "Terraform acceptance tests",
107-
LFSEnabled: true,
108-
Parent: &group,
122+
Name: fmt.Sprintf("nfoo-name-%d", rInt),
123+
Path: fmt.Sprintf("nfoo-path-%d", rInt),
124+
Description: "Terraform acceptance tests",
125+
LFSEnabled: true,
126+
Visibility: "public", // default value
127+
ProjectCreationLevel: "maintainer", // default value
128+
SubGroupCreationLevel: "owner", // default value
129+
TwoFactorGracePeriod: 48, // default value
130+
Parent: &group,
109131
}),
110132
),
111133
},
@@ -116,11 +138,15 @@ func TestAccGitlabGroup_nested(t *testing.T) {
116138
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
117139
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
118140
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
119-
Name: fmt.Sprintf("nfoo-name-%d", rInt),
120-
Path: fmt.Sprintf("nfoo-path-%d", rInt),
121-
Description: "Terraform acceptance tests - new parent",
122-
LFSEnabled: true,
123-
Parent: &group2,
141+
Name: fmt.Sprintf("nfoo-name-%d", rInt),
142+
Path: fmt.Sprintf("nfoo-path-%d", rInt),
143+
Description: "Terraform acceptance tests - new parent",
144+
LFSEnabled: true,
145+
Visibility: "public", // default value
146+
ProjectCreationLevel: "maintainer", // default value
147+
SubGroupCreationLevel: "owner", // default value
148+
TwoFactorGracePeriod: 48, // default value
149+
Parent: &group2,
124150
}),
125151
),
126152
},
@@ -131,10 +157,14 @@ func TestAccGitlabGroup_nested(t *testing.T) {
131157
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
132158
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
133159
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
134-
Name: fmt.Sprintf("nfoo-name-%d", rInt),
135-
Path: fmt.Sprintf("nfoo-path-%d", rInt),
136-
Description: "Terraform acceptance tests - updated",
137-
LFSEnabled: true,
160+
Name: fmt.Sprintf("nfoo-name-%d", rInt),
161+
Path: fmt.Sprintf("nfoo-path-%d", rInt),
162+
Description: "Terraform acceptance tests - updated",
163+
LFSEnabled: true,
164+
Visibility: "public", // default value
165+
ProjectCreationLevel: "maintainer", // default value
166+
SubGroupCreationLevel: "owner", // default value
167+
TwoFactorGracePeriod: 48, // default value
138168
}),
139169
),
140170
},
@@ -150,6 +180,10 @@ func TestAccGitlabGroup_nested(t *testing.T) {
150180
// Path: fmt.Sprintf("nfoo-path-%d", rInt),
151181
// Description: "Terraform acceptance tests",
152182
// LFSEnabled: true,
183+
// Visibility: "public", // default value
184+
// ProjectCreationLevel: "maintainer", // default value
185+
// SubGroupCreationLevel: "owner", // default value
186+
// TwoFactorGracePeriod: 48, // default value
153187
// Parent: &group,
154188
// }),
155189
// ),
@@ -228,12 +262,21 @@ func testAccCheckGitlabGroupExists(n string, group *gitlab.Group) resource.TestC
228262
}
229263

230264
type testAccGitlabGroupExpectedAttributes struct {
231-
Name string
232-
Path string
233-
Description string
234-
Parent *gitlab.Group
235-
LFSEnabled bool
236-
RequestAccessEnabled bool
265+
Name string
266+
Path string
267+
Description string
268+
Parent *gitlab.Group
269+
LFSEnabled bool
270+
RequestAccessEnabled bool
271+
Visibility gitlab.VisibilityValue
272+
ShareWithGroupLock bool
273+
AutoDevopsEnabled bool
274+
EmailsDisabled bool
275+
MentionsDisabled bool
276+
ProjectCreationLevel gitlab.ProjectCreationLevelValue
277+
SubGroupCreationLevel gitlab.SubGroupCreationLevelValue
278+
RequireTwoFactorAuth bool
279+
TwoFactorGracePeriod int
237280
}
238281

239282
func testAccCheckGitlabGroupAttributes(group *gitlab.Group, want *testAccGitlabGroupExpectedAttributes) resource.TestCheckFunc {
@@ -254,10 +297,46 @@ func testAccCheckGitlabGroupAttributes(group *gitlab.Group, want *testAccGitlabG
254297
return fmt.Errorf("got lfs_enabled %t; want %t", group.LFSEnabled, want.LFSEnabled)
255298
}
256299

300+
if group.Visibility != want.Visibility {
301+
return fmt.Errorf("got request_visibility_level: %q; want %q", group.Visibility, want.Visibility)
302+
}
303+
304+
if group.AutoDevopsEnabled != want.AutoDevopsEnabled {
305+
return fmt.Errorf("got request_auto_devops_enabled: %t; want %t", group.AutoDevopsEnabled, want.AutoDevopsEnabled)
306+
}
307+
308+
if group.EmailsDisabled != want.EmailsDisabled {
309+
return fmt.Errorf("got request_emails_disabled: %t; want %t", group.EmailsDisabled, want.EmailsDisabled)
310+
}
311+
312+
if group.MentionsDisabled != want.MentionsDisabled {
313+
return fmt.Errorf("got request_mentions_disabled: %t; want %t", group.MentionsDisabled, want.MentionsDisabled)
314+
}
315+
257316
if group.RequestAccessEnabled != want.RequestAccessEnabled {
258317
return fmt.Errorf("got request_access_enabled %t; want %t", group.RequestAccessEnabled, want.RequestAccessEnabled)
259318
}
260319

320+
if group.ProjectCreationLevel != want.ProjectCreationLevel {
321+
return fmt.Errorf("got project_creation_level %s; want %s", group.ProjectCreationLevel, want.ProjectCreationLevel)
322+
}
323+
324+
if group.SubGroupCreationLevel != want.SubGroupCreationLevel {
325+
return fmt.Errorf("got subgroup_creation_level %s; want %s", group.SubGroupCreationLevel, want.SubGroupCreationLevel)
326+
}
327+
328+
if group.RequireTwoFactorAuth != want.RequireTwoFactorAuth {
329+
return fmt.Errorf("got require_two_factor_authentication %t; want %t", group.RequireTwoFactorAuth, want.RequireTwoFactorAuth)
330+
}
331+
332+
if group.TwoFactorGracePeriod != want.TwoFactorGracePeriod {
333+
return fmt.Errorf("got two_factor_grace_period %d; want %d", group.TwoFactorGracePeriod, want.TwoFactorGracePeriod)
334+
}
335+
336+
if group.ShareWithGroupLock != want.ShareWithGroupLock {
337+
return fmt.Errorf("got share_with_group_lock %t; want %t", group.ShareWithGroupLock, want.ShareWithGroupLock)
338+
}
339+
261340
if want.Parent != nil {
262341
if group.ParentID != want.Parent.ID {
263342
return fmt.Errorf("got parent_id %d; want %d", group.ParentID, want.Parent.ID)
@@ -318,6 +397,14 @@ resource "gitlab_group" "foo" {
318397
description = "Terraform acceptance tests! Updated description"
319398
lfs_enabled = false
320399
request_access_enabled = true
400+
project_creation_level = "developer"
401+
subgroup_creation_level = "maintainer"
402+
require_two_factor_authentication = true
403+
two_factor_grace_period = 56
404+
auto_devops_enabled = true
405+
emails_disabled = true
406+
mentions_disabled = true
407+
share_with_group_lock = true
321408
322409
# So that acceptance tests can be run in a gitlab organization
323410
# with no billing

0 commit comments

Comments
 (0)