Skip to content

Commit fc84cc3

Browse files
authored
Merge pull request #806 from timofurrer/bugfix/mark-project-id-computed
Properly allow arguments `id` or `path_with_namespace` for project data source
2 parents 84d729e + 481d8d4 commit fc84cc3

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

gitlab/data_source_gitlab_project.go

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,13 @@ func dataSourceGitlabProject() *schema.Resource {
1919
Schema: map[string]*schema.Schema{
2020
"id": {
2121
Type: schema.TypeString,
22-
Required: true,
22+
Optional: true,
23+
Computed: true,
24+
ExactlyOneOf: []string{
25+
"id",
26+
"path_with_namespace",
27+
},
28+
Description: "The ID of the project",
2329
},
2430
"name": {
2531
Type: schema.TypeString,
@@ -31,7 +37,13 @@ func dataSourceGitlabProject() *schema.Resource {
3137
},
3238
"path_with_namespace": {
3339
Type: schema.TypeString,
40+
Optional: true,
3441
Computed: true,
42+
ExactlyOneOf: []string{
43+
"id",
44+
"path_with_namespace",
45+
},
46+
Description: "The full path of the project including the namespace",
3547
},
3648
"description": {
3749
Type: schema.TypeString,
@@ -163,9 +175,16 @@ func dataSourceGitlabProjectRead(ctx context.Context, d *schema.ResourceData, me
163175

164176
log.Printf("[INFO] Reading Gitlab project")
165177

166-
v, _ := d.GetOk("id")
178+
var pid interface{}
179+
if v, ok := d.GetOk("id"); ok {
180+
pid = v
181+
} else if v, ok := d.GetOk("path_with_namespace"); ok {
182+
pid = v
183+
} else {
184+
return diag.Errorf("Must specify either id or path_with_namespace")
185+
}
167186

168-
found, _, err := client.Projects.GetProject(v, nil, gitlab.WithContext(ctx))
187+
found, _, err := client.Projects.GetProject(pid, nil, gitlab.WithContext(ctx))
169188
if err != nil {
170189
return diag.FromErr(err)
171190
}

gitlab/data_source_gitlab_project_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ resource "gitlab_project" "test"{
8383
}
8484
8585
data "gitlab_project" "foo" {
86-
id = gitlab_project.test.path_with_namespace
86+
path_with_namespace = gitlab_project.test.path_with_namespace
8787
}
8888
`, projectname, projectname)
8989
}

0 commit comments

Comments
 (0)