Skip to content

Commit e34eb3f

Browse files
authored
Merge pull request #30 from roidelapluie/imp
Enable gitlab_project import
2 parents d613f20 + 3448929 commit e34eb3f

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

gitlab/resource_gitlab_project.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ func resourceGitlabProject() *schema.Resource {
1717
Read: resourceGitlabProjectRead,
1818
Update: resourceGitlabProjectUpdate,
1919
Delete: resourceGitlabProjectDelete,
20+
Importer: &schema.ResourceImporter{
21+
State: schema.ImportStatePassthrough,
22+
},
2023

2124
Schema: map[string]*schema.Schema{
2225
"name": {
@@ -36,6 +39,8 @@ func resourceGitlabProject() *schema.Resource {
3639
"namespace_id": {
3740
Type: schema.TypeInt,
3841
Optional: true,
42+
ForceNew: true,
43+
Computed: true,
3944
},
4045
"description": {
4146
Type: schema.TypeString,
@@ -98,6 +103,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
98103
d.Set("wiki_enabled", project.WikiEnabled)
99104
d.Set("snippets_enabled", project.SnippetsEnabled)
100105
d.Set("visibility_level", string(project.Visibility))
106+
d.Set("namespace_id", project.Namespace.ID)
101107

102108
d.Set("ssh_url_to_repo", project.SSHURLToRepo)
103109
d.Set("http_url_to_repo", project.HTTPURLToRepo)

gitlab/resource_gitlab_project_test.go

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,46 @@ func TestAccGitlabProject_basic(t *testing.T) {
7070
})
7171
}
7272

73+
func TestAccGitlabProject_import(t *testing.T) {
74+
rInt := acctest.RandInt()
75+
76+
resource.Test(t, resource.TestCase{
77+
PreCheck: func() { testAccPreCheck(t) },
78+
Providers: testAccProviders,
79+
CheckDestroy: testAccCheckGitlabProjectDestroy,
80+
Steps: []resource.TestStep{
81+
{
82+
Config: testAccGitlabProjectConfig(rInt),
83+
},
84+
{
85+
ResourceName: "gitlab_project.foo",
86+
ImportState: true,
87+
ImportStateVerify: true,
88+
},
89+
},
90+
})
91+
}
92+
93+
func TestAccGitlabProject_nestedImport(t *testing.T) {
94+
rInt := acctest.RandInt()
95+
96+
resource.Test(t, resource.TestCase{
97+
PreCheck: func() { testAccPreCheck(t) },
98+
Providers: testAccProviders,
99+
CheckDestroy: testAccCheckGitlabProjectDestroy,
100+
Steps: []resource.TestStep{
101+
{
102+
Config: testAccGitlabProjectInGroupConfig(rInt),
103+
},
104+
{
105+
ResourceName: "gitlab_project.foo",
106+
ImportState: true,
107+
ImportStateVerify: true,
108+
},
109+
},
110+
})
111+
}
112+
73113
func testAccCheckGitlabProjectExists(n string, project *gitlab.Project) resource.TestCheckFunc {
74114
return func(s *terraform.State) error {
75115
rs, ok := s.RootModule().Resources[n]
@@ -166,6 +206,26 @@ func testAccCheckGitlabProjectDestroy(s *terraform.State) error {
166206
return nil
167207
}
168208

209+
func testAccGitlabProjectInGroupConfig(rInt int) string {
210+
return fmt.Sprintf(`
211+
resource "gitlab_group" "foo" {
212+
name = "foogroup-%d"
213+
path = "foogroup-%d"
214+
visibility_level = "public"
215+
}
216+
217+
resource "gitlab_project" "foo" {
218+
name = "foo-%d"
219+
description = "Terraform acceptance tests"
220+
namespace_id = "${gitlab_group.foo.id}"
221+
222+
# So that acceptance tests can be run in a gitlab organization
223+
# with no billing
224+
visibility_level = "public"
225+
}
226+
`, rInt, rInt, rInt)
227+
}
228+
169229
func testAccGitlabProjectConfig(rInt int) string {
170230
return fmt.Sprintf(`
171231
resource "gitlab_project" "foo" {

0 commit comments

Comments
 (0)