Skip to content

Commit 3448929

Browse files
author
Julien Pivotto
committed
Enable gitlab_project import
refs #10 Signed-off-by: Julien Pivotto <[email protected]>
1 parent 4742657 commit 3448929

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": {
@@ -26,6 +29,8 @@ func resourceGitlabProject() *schema.Resource {
2629
"namespace_id": {
2730
Type: schema.TypeInt,
2831
Optional: true,
32+
ForceNew: true,
33+
Computed: true,
2934
},
3035
"description": {
3136
Type: schema.TypeString,
@@ -87,6 +92,7 @@ func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Pro
8792
d.Set("wiki_enabled", project.WikiEnabled)
8893
d.Set("snippets_enabled", project.SnippetsEnabled)
8994
d.Set("visibility_level", string(project.Visibility))
95+
d.Set("namespace_id", project.Namespace.ID)
9096

9197
d.Set("ssh_url_to_repo", project.SSHURLToRepo)
9298
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
@@ -67,6 +67,46 @@ func TestAccGitlabProject_basic(t *testing.T) {
6767
})
6868
}
6969

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

202+
func testAccGitlabProjectInGroupConfig(rInt int) string {
203+
return fmt.Sprintf(`
204+
resource "gitlab_group" "foo" {
205+
name = "foogroup-%d"
206+
path = "foogroup-%d"
207+
visibility_level = "public"
208+
}
209+
210+
resource "gitlab_project" "foo" {
211+
name = "foo-%d"
212+
description = "Terraform acceptance tests"
213+
namespace_id = "${gitlab_group.foo.id}"
214+
215+
# So that acceptance tests can be run in a gitlab organization
216+
# with no billing
217+
visibility_level = "public"
218+
}
219+
`, rInt, rInt, rInt)
220+
}
221+
162222
func testAccGitlabProjectConfig(rInt int) string {
163223
return fmt.Sprintf(`
164224
resource "gitlab_project" "foo" {

0 commit comments

Comments
 (0)