Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More group options #362

Merged
merged 29 commits into from
Sep 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
4669ff8
rebase
justinkillen Jul 19, 2020
1bd46c0
rebase
justinkillen Jul 25, 2020
7e01713
whitespace tweaks
justinkillen Jul 25, 2020
8c2d76c
more tweaks
justinkillen Jul 25, 2020
cc47256
update tests - default visibility is public
justinkillen Jul 25, 2020
58b677e
make fmt
justinkillen Jul 25, 2020
81a065b
set defaults
justinkillen Jul 26, 2020
8141b9c
clear computed
justinkillen Jul 26, 2020
0b2551f
defaults
justinkillen Jul 26, 2020
84d8b8f
default
justinkillen Jul 26, 2020
b6f9617
more test fixes
justinkillen Jul 26, 2020
7cc6d63
more defaults
justinkillen Jul 26, 2020
3831d43
remove default on runner limits; set to Computed
justinkillen Jul 26, 2020
3b614e5
tweak tests
justinkillen Jul 26, 2020
7074b62
fix make test failures
justinkillen Jul 26, 2020
de21f9e
set default
justinkillen Jul 26, 2020
7d2aeea
explicit wants
justinkillen Jul 26, 2020
f643a2e
explicit wants
justinkillen Jul 26, 2020
b1cd1ab
fix test values
justinkillen Jul 26, 2020
c9182d0
update test want values to defaults
justinkillen Jul 26, 2020
391a4e5
shared runners not Compute
justinkillen Jul 26, 2020
ce558ad
dropping runner minutes support in this PR
justinkillen Jul 26, 2020
e284c9f
update docs
justinkillen Jul 26, 2020
e7da9f8
sync defaults
justinkillen Jul 26, 2020
6d467ed
fix format
justinkillen Jul 26, 2020
da794c4
fix nested tests
justinkillen Jul 26, 2020
0529e31
maybe order matters?
justinkillen Jul 26, 2020
b911967
Update website/docs/r/group.html.markdown
justinkillen Sep 11, 2020
3abf134
Update website/docs/r/group.html.markdown
justinkillen Sep 11, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion gitlab/resource_gitlab_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,51 @@ func resourceGitlabGroup() *schema.Resource {
"visibility_level": {
Type: schema.TypeString,
Optional: true,
Computed: true,
Default: "private",
armsnyder marked this conversation as resolved.
Show resolved Hide resolved
ValidateFunc: validation.StringInSlice([]string{"private", "internal", "public"}, true),
},
"share_with_group_lock": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"project_creation_level": {
Type: schema.TypeString,
Optional: true,
Default: "maintainer",
ValidateFunc: validation.StringInSlice([]string{"noone", "maintainer", "developer"}, true),
},
"auto_devops_enabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"emails_disabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"mentions_disabled": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"subgroup_creation_level": {
Type: schema.TypeString,
Optional: true,
Default: "owner",
ValidateFunc: validation.StringInSlice([]string{"owner", "maintainer"}, true),
},
"require_two_factor_authentication": {
Type: schema.TypeBool,
Optional: true,
Default: false,
},
"two_factor_grace_period": {
Type: schema.TypeInt,
Optional: true,
Default: 48,
},
"parent_id": {
Type: schema.TypeInt,
Optional: true,
Expand Down Expand Up @@ -99,6 +141,38 @@ func resourceGitlabGroupCreate(d *schema.ResourceData, meta interface{}) error {
options.Visibility = stringToVisibilityLevel(v.(string))
}

if v, ok := d.GetOk("share_with_group_lock"); ok {
options.ShareWithGroupLock = gitlab.Bool(v.(bool))
}

if v, ok := d.GetOk("require_two_factor_authentication"); ok {
options.RequireTwoFactorAuth = gitlab.Bool(v.(bool))
}

if v, ok := d.GetOk("two_factor_grace_period"); ok {
options.TwoFactorGracePeriod = gitlab.Int(v.(int))
}

if v, ok := d.GetOk("project_creation_level"); ok {
options.ProjectCreationLevel = stringToProjectCreationLevel(v.(string))
}

if v, ok := d.GetOk("auto_devops_enabled"); ok {
options.AutoDevopsEnabled = gitlab.Bool(v.(bool))
}

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

if v, ok := d.GetOk("emails_disabled"); ok {
options.EmailsDisabled = gitlab.Bool(v.(bool))
}

if v, ok := d.GetOk("mentions_disabled"); ok {
options.MentionsDisabled = gitlab.Bool(v.(bool))
}

if v, ok := d.GetOk("parent_id"); ok {
options.ParentID = gitlab.Int(v.(int))
}
Expand Down Expand Up @@ -144,8 +218,16 @@ func resourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
d.Set("lfs_enabled", group.LFSEnabled)
d.Set("request_access_enabled", group.RequestAccessEnabled)
d.Set("visibility_level", group.Visibility)
d.Set("project_creation_level", group.ProjectCreationLevel)
d.Set("subgroup_creation_level", group.SubGroupCreationLevel)
d.Set("require_two_factor_authentication", group.RequireTwoFactorAuth)
d.Set("two_factor_grace_period", group.TwoFactorGracePeriod)
d.Set("auto_devops_enabled", group.AutoDevopsEnabled)
d.Set("emails_disabled", group.EmailsDisabled)
d.Set("mentions_disabled", group.MentionsDisabled)
d.Set("parent_id", group.ParentID)
d.Set("runners_token", group.RunnersToken)
d.Set("share_with_group_lock", group.ShareWithGroupLock)

return nil
}
Expand Down Expand Up @@ -181,6 +263,38 @@ func resourceGitlabGroupUpdate(d *schema.ResourceData, meta interface{}) error {
options.Visibility = stringToVisibilityLevel(v.(string))
}

if d.HasChange("project_creation_level") {
options.ProjectCreationLevel = stringToProjectCreationLevel(d.Get("project_creation_level").(string))
}

if d.HasChange("subgroup_creation_level") {
options.SubGroupCreationLevel = stringToSubGroupCreationLevel(d.Get("subgroup_creation_level").(string))
}

if d.HasChange("require_two_factor_authentication") {
options.RequireTwoFactorAuth = gitlab.Bool(d.Get("require_two_factor_authentication").(bool))
}

if d.HasChange("two_factor_grace_period") {
options.TwoFactorGracePeriod = gitlab.Int(d.Get("two_factor_grace_period").(int))
}

if d.HasChange("auto_devops_enabled") {
options.AutoDevopsEnabled = gitlab.Bool(d.Get("auto_devops_enabled").(bool))
}

if d.HasChange("emails_disabled") {
options.EmailsDisabled = gitlab.Bool(d.Get("emails_disabled").(bool))
}

if d.HasChange("mentions_disabled") {
options.MentionsDisabled = gitlab.Bool(d.Get("mentions_disabled").(bool))
}

if d.HasChange("share_with_group_lock") {
options.ShareWithGroupLock = gitlab.Bool(d.Get("share_with_group_lock").(bool))
}

log.Printf("[DEBUG] update gitlab group %s", d.Id())

_, _, err := client.Groups.UpdateGroup(d.Id(), options)
Expand Down
153 changes: 120 additions & 33 deletions gitlab/resource_gitlab_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ func TestAccGitlabGroup_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("foo-name-%d", rInt),
Path: fmt.Sprintf("foo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Name: fmt.Sprintf("foo-name-%d", rInt),
Path: fmt.Sprintf("foo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Visibility: "public", // default value
ProjectCreationLevel: "maintainer", // default value
SubGroupCreationLevel: "owner", // default value
TwoFactorGracePeriod: 48, // default value
}),
),
},
Expand All @@ -39,23 +43,37 @@ func TestAccGitlabGroup_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("bar-name-%d", rInt),
Path: fmt.Sprintf("bar-path-%d", rInt),
Description: "Terraform acceptance tests! Updated description",
RequestAccessEnabled: true,
Name: fmt.Sprintf("bar-name-%d", rInt),
Path: fmt.Sprintf("bar-path-%d", rInt),
Description: "Terraform acceptance tests! Updated description",
LFSEnabled: false,
Visibility: "public", // default value
RequestAccessEnabled: true,
ProjectCreationLevel: "developer",
SubGroupCreationLevel: "maintainer",
RequireTwoFactorAuth: true,
TwoFactorGracePeriod: 56,
AutoDevopsEnabled: true,
EmailsDisabled: true,
MentionsDisabled: true,
ShareWithGroupLock: true,
}),
),
},
// Update the group to put the anem and description back
// Update the group to put the name and description back
{
Config: testAccGitlabGroupConfig(rInt),
Check: resource.ComposeTestCheckFunc(
testAccCheckGitlabGroupExists("gitlab_group.foo", &group),
testAccCheckGitlabGroupAttributes(&group, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("foo-name-%d", rInt),
Path: fmt.Sprintf("foo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Name: fmt.Sprintf("foo-name-%d", rInt),
Path: fmt.Sprintf("foo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Visibility: "public", // default value
ProjectCreationLevel: "maintainer", // default value
SubGroupCreationLevel: "owner", // default value
TwoFactorGracePeriod: 48, // default value
}),
),
},
Expand Down Expand Up @@ -101,11 +119,15 @@ func TestAccGitlabGroup_nested(t *testing.T) {
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Parent: &group,
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests",
LFSEnabled: true,
Visibility: "public", // default value
ProjectCreationLevel: "maintainer", // default value
SubGroupCreationLevel: "owner", // default value
TwoFactorGracePeriod: 48, // default value
Parent: &group,
}),
),
},
Expand All @@ -116,11 +138,15 @@ func TestAccGitlabGroup_nested(t *testing.T) {
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests - new parent",
LFSEnabled: true,
Parent: &group2,
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests - new parent",
LFSEnabled: true,
Visibility: "public", // default value
ProjectCreationLevel: "maintainer", // default value
SubGroupCreationLevel: "owner", // default value
TwoFactorGracePeriod: 48, // default value
Parent: &group2,
}),
),
},
Expand All @@ -131,10 +157,14 @@ func TestAccGitlabGroup_nested(t *testing.T) {
testAccCheckGitlabGroupExists("gitlab_group.foo2", &group2),
testAccCheckGitlabGroupExists("gitlab_group.nested_foo", &nestedGroup),
testAccCheckGitlabGroupAttributes(&nestedGroup, &testAccGitlabGroupExpectedAttributes{
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests - updated",
LFSEnabled: true,
Name: fmt.Sprintf("nfoo-name-%d", rInt),
Path: fmt.Sprintf("nfoo-path-%d", rInt),
Description: "Terraform acceptance tests - updated",
LFSEnabled: true,
Visibility: "public", // default value
ProjectCreationLevel: "maintainer", // default value
SubGroupCreationLevel: "owner", // default value
TwoFactorGracePeriod: 48, // default value
}),
),
},
Expand All @@ -150,6 +180,10 @@ func TestAccGitlabGroup_nested(t *testing.T) {
// Path: fmt.Sprintf("nfoo-path-%d", rInt),
// Description: "Terraform acceptance tests",
// LFSEnabled: true,
// Visibility: "public", // default value
// ProjectCreationLevel: "maintainer", // default value
// SubGroupCreationLevel: "owner", // default value
// TwoFactorGracePeriod: 48, // default value
// Parent: &group,
// }),
// ),
Expand Down Expand Up @@ -228,12 +262,21 @@ func testAccCheckGitlabGroupExists(n string, group *gitlab.Group) resource.TestC
}

type testAccGitlabGroupExpectedAttributes struct {
Name string
Path string
Description string
Parent *gitlab.Group
LFSEnabled bool
RequestAccessEnabled bool
Name string
Path string
Description string
Parent *gitlab.Group
LFSEnabled bool
RequestAccessEnabled bool
Visibility gitlab.VisibilityValue
ShareWithGroupLock bool
AutoDevopsEnabled bool
EmailsDisabled bool
MentionsDisabled bool
ProjectCreationLevel gitlab.ProjectCreationLevelValue
SubGroupCreationLevel gitlab.SubGroupCreationLevelValue
RequireTwoFactorAuth bool
TwoFactorGracePeriod int
}

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

if group.Visibility != want.Visibility {
return fmt.Errorf("got request_visibility_level: %q; want %q", group.Visibility, want.Visibility)
}

if group.AutoDevopsEnabled != want.AutoDevopsEnabled {
return fmt.Errorf("got request_auto_devops_enabled: %t; want %t", group.AutoDevopsEnabled, want.AutoDevopsEnabled)
}

if group.EmailsDisabled != want.EmailsDisabled {
return fmt.Errorf("got request_emails_disabled: %t; want %t", group.EmailsDisabled, want.EmailsDisabled)
}

if group.MentionsDisabled != want.MentionsDisabled {
return fmt.Errorf("got request_mentions_disabled: %t; want %t", group.MentionsDisabled, want.MentionsDisabled)
}

if group.RequestAccessEnabled != want.RequestAccessEnabled {
return fmt.Errorf("got request_access_enabled %t; want %t", group.RequestAccessEnabled, want.RequestAccessEnabled)
}

if group.ProjectCreationLevel != want.ProjectCreationLevel {
return fmt.Errorf("got project_creation_level %s; want %s", group.ProjectCreationLevel, want.ProjectCreationLevel)
}

if group.SubGroupCreationLevel != want.SubGroupCreationLevel {
return fmt.Errorf("got subgroup_creation_level %s; want %s", group.SubGroupCreationLevel, want.SubGroupCreationLevel)
}

if group.RequireTwoFactorAuth != want.RequireTwoFactorAuth {
return fmt.Errorf("got require_two_factor_authentication %t; want %t", group.RequireTwoFactorAuth, want.RequireTwoFactorAuth)
}

if group.TwoFactorGracePeriod != want.TwoFactorGracePeriod {
return fmt.Errorf("got two_factor_grace_period %d; want %d", group.TwoFactorGracePeriod, want.TwoFactorGracePeriod)
}

if group.ShareWithGroupLock != want.ShareWithGroupLock {
return fmt.Errorf("got share_with_group_lock %t; want %t", group.ShareWithGroupLock, want.ShareWithGroupLock)
}

if want.Parent != nil {
if group.ParentID != want.Parent.ID {
return fmt.Errorf("got parent_id %d; want %d", group.ParentID, want.Parent.ID)
Expand Down Expand Up @@ -318,6 +397,14 @@ resource "gitlab_group" "foo" {
description = "Terraform acceptance tests! Updated description"
lfs_enabled = false
request_access_enabled = true
project_creation_level = "developer"
subgroup_creation_level = "maintainer"
require_two_factor_authentication = true
two_factor_grace_period = 56
auto_devops_enabled = true
emails_disabled = true
mentions_disabled = true
share_with_group_lock = true

# So that acceptance tests can be run in a gitlab organization
# with no billing
Expand Down
Loading