Skip to content

Commit 112aca4

Browse files
authored
Merge pull request #31 from roidelapluie/groupimport
gitlab_group: enable imports
2 parents 58aa469 + 85c8872 commit 112aca4

File tree

2 files changed

+29
-3
lines changed

2 files changed

+29
-3
lines changed

gitlab/resource_gitlab_group.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ func resourceGitlabGroup() *schema.Resource {
1515
Read: resourceGitlabGroupRead,
1616
Update: resourceGitlabGroupUpdate,
1717
Delete: resourceGitlabGroupDelete,
18+
Importer: &schema.ResourceImporter{
19+
State: schema.ImportStatePassthrough,
20+
},
1821

1922
Schema: map[string]*schema.Schema{
2023
"name": {
@@ -42,8 +45,8 @@ func resourceGitlabGroup() *schema.Resource {
4245
"visibility_level": {
4346
Type: schema.TypeString,
4447
Optional: true,
48+
Computed: true,
4549
ValidateFunc: validation.StringInSlice([]string{"private", "internal", "public"}, true),
46-
Default: "private",
4750
},
4851
},
4952
}
@@ -101,6 +104,7 @@ func resourceGitlabGroupRead(d *schema.ResourceData, meta interface{}) error {
101104
d.Set("description", group.Description)
102105
d.Set("lfs_enabled", group.LFSEnabled)
103106
d.Set("request_access_enabled", group.RequestAccessEnabled)
107+
d.Set("visibility_level", group.Visibility)
104108

105109
return nil
106110
}
@@ -130,8 +134,10 @@ func resourceGitlabGroupUpdate(d *schema.ResourceData, meta interface{}) error {
130134
options.RequestAccessEnabled = gitlab.Bool(d.Get("request_access_enabled").(bool))
131135
}
132136

133-
if d.HasChange("visibility_level") {
134-
options.Visibility = stringToVisibilityLevel(d.Get("visibility_level").(string))
137+
// Always set visibility ; workaround for
138+
// https://gitlab.com/gitlab-org/gitlab-ce/issues/38459
139+
if v, ok := d.GetOk("visibility_level"); ok {
140+
options.Visibility = stringToVisibilityLevel(v.(string))
135141
}
136142

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

gitlab/resource_gitlab_group_test.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,26 @@ func TestAccGitlabGroup_basic(t *testing.T) {
6262
})
6363
}
6464

65+
func TestAccGitlabGroup_import(t *testing.T) {
66+
rInt := acctest.RandInt()
67+
68+
resource.Test(t, resource.TestCase{
69+
PreCheck: func() { testAccPreCheck(t) },
70+
Providers: testAccProviders,
71+
CheckDestroy: testAccCheckGitlabGroupDestroy,
72+
Steps: []resource.TestStep{
73+
{
74+
Config: testAccGitlabGroupConfig(rInt),
75+
},
76+
{
77+
ResourceName: "gitlab_group.foo",
78+
ImportState: true,
79+
ImportStateVerify: true,
80+
},
81+
},
82+
})
83+
}
84+
6585
func testAccCheckGitlabGroupExists(n string, group *gitlab.Group) resource.TestCheckFunc {
6686
return func(s *terraform.State) error {
6787
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)