Skip to content

Commit c458fe8

Browse files
author
Julien Pivotto
committed
gitlab_project: Add support for the path field
Signed-off-by: Julien Pivotto <[email protected]>
1 parent 4742657 commit c458fe8

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

gitlab/resource_gitlab_project.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,16 @@ func resourceGitlabProject() *schema.Resource {
2323
Type: schema.TypeString,
2424
Required: true,
2525
},
26+
"path": {
27+
Type: schema.TypeString,
28+
Optional: true,
29+
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool {
30+
if new == "" {
31+
return true
32+
}
33+
return old == new
34+
},
35+
},
2636
"namespace_id": {
2737
Type: schema.TypeInt,
2838
Optional: true,
@@ -80,6 +90,7 @@ func resourceGitlabProject() *schema.Resource {
8090

8191
func resourceGitlabProjectSetToState(d *schema.ResourceData, project *gitlab.Project) {
8292
d.Set("name", project.Name)
93+
d.Set("path", project.Path)
8394
d.Set("description", project.Description)
8495
d.Set("default_branch", project.DefaultBranch)
8596
d.Set("issues_enabled", project.IssuesEnabled)
@@ -104,6 +115,10 @@ func resourceGitlabProjectCreate(d *schema.ResourceData, meta interface{}) error
104115
Visibility: stringToVisibilityLevel(d.Get("visibility_level").(string)),
105116
}
106117

118+
if v, ok := d.GetOk("path"); ok {
119+
options.Path = gitlab.String(v.(string))
120+
}
121+
107122
if v, ok := d.GetOk("namespace_id"); ok {
108123
options.NamespaceID = gitlab.Int(v.(int))
109124
}
@@ -152,6 +167,10 @@ func resourceGitlabProjectUpdate(d *schema.ResourceData, meta interface{}) error
152167
options.Name = gitlab.String(d.Get("name").(string))
153168
}
154169

170+
if d.HasChange("path") && (d.Get("path").(string) != "") {
171+
options.Path = gitlab.String(d.Get("path").(string))
172+
}
173+
155174
if d.HasChange("description") {
156175
options.Description = gitlab.String(d.Get("description").(string))
157176
}

gitlab/resource_gitlab_project_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
2626
testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
2727
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
2828
Name: fmt.Sprintf("foo-%d", rInt),
29+
Path: fmt.Sprintf("foo.%d", rInt),
2930
Description: "Terraform acceptance tests",
3031
IssuesEnabled: true,
3132
MergeRequestsEnabled: true,
@@ -42,6 +43,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
4243
testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
4344
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
4445
Name: fmt.Sprintf("foo-%d", rInt),
46+
Path: fmt.Sprintf("foo.%d", rInt),
4547
Description: "Terraform acceptance tests!",
4648
Visibility: gitlab.PublicVisibility,
4749
}),
@@ -54,6 +56,7 @@ func TestAccGitlabProject_basic(t *testing.T) {
5456
testAccCheckGitlabProjectExists("gitlab_project.foo", &project),
5557
testAccCheckGitlabProjectAttributes(&project, &testAccGitlabProjectExpectedAttributes{
5658
Name: fmt.Sprintf("foo-%d", rInt),
59+
Path: fmt.Sprintf("foo.%d", rInt),
5760
Description: "Terraform acceptance tests",
5861
IssuesEnabled: true,
5962
MergeRequestsEnabled: true,
@@ -91,6 +94,7 @@ func testAccCheckGitlabProjectExists(n string, project *gitlab.Project) resource
9194

9295
type testAccGitlabProjectExpectedAttributes struct {
9396
Name string
97+
Path string
9498
Description string
9599
DefaultBranch string
96100
IssuesEnabled bool
@@ -105,6 +109,9 @@ func testAccCheckGitlabProjectAttributes(project *gitlab.Project, want *testAccG
105109
if project.Name != want.Name {
106110
return fmt.Errorf("got repo %q; want %q", project.Name, want.Name)
107111
}
112+
if project.Path != want.Path {
113+
return fmt.Errorf("got repo %q; want %q", project.Path, want.Path)
114+
}
108115
if project.Description != want.Description {
109116
return fmt.Errorf("got description %q; want %q", project.Description, want.Description)
110117
}
@@ -163,19 +170,21 @@ func testAccGitlabProjectConfig(rInt int) string {
163170
return fmt.Sprintf(`
164171
resource "gitlab_project" "foo" {
165172
name = "foo-%d"
173+
path = "foo.%d"
166174
description = "Terraform acceptance tests"
167175
168176
# So that acceptance tests can be run in a gitlab organization
169177
# with no billing
170178
visibility_level = "public"
171179
}
172-
`, rInt)
180+
`, rInt, rInt)
173181
}
174182

175183
func testAccGitlabProjectUpdateConfig(rInt int) string {
176184
return fmt.Sprintf(`
177185
resource "gitlab_project" "foo" {
178186
name = "foo-%d"
187+
path = "foo.%d"
179188
description = "Terraform acceptance tests!"
180189
181190
# So that acceptance tests can be run in a gitlab organization
@@ -187,5 +196,5 @@ resource "gitlab_project" "foo" {
187196
wiki_enabled = false
188197
snippets_enabled = false
189198
}
190-
`, rInt)
199+
`, rInt, rInt)
191200
}

website/docs/r/project.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ The following arguments are supported:
2929

3030
* `name` - (Required) The name of the project.
3131

32+
* `path` - (Optional) The path of the repository.
33+
3234
* `namespace_id` - (Optional) The namespace (group or user) of the project. Defaults to your user.
3335
See [`gitlab_group`](group.html) for an example.
3436

0 commit comments

Comments
 (0)