Skip to content

Commit 68c4a0e

Browse files
authored
Merge pull request #1429 from 1natedawg/main
d/tfe_project: Output workspace names
2 parents f88988b + 9b9580d commit 68c4a0e

File tree

4 files changed

+19
-2
lines changed

4 files changed

+19
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Unreleased
22

3+
ENHANCEMENTS:
4+
* `d/tfe_project`: Add `workspace_names` attribute, by @1natedawg [#1429](https://github.com/hashicorp/terraform-provider-tfe/pull/1429)
5+
36
BUG FIXES:
47
* `r/tfe_workspace` html_url is now planned to be recomputed when `name` changes. Previously, changed values would show up on the next plan, by @brandonc [1422](https://github.com/hashicorp/terraform-provider-tfe/issues/1422)
58

internal/provider/data_source_project.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ func dataSourceTFEProject() *schema.Resource {
4444
Computed: true,
4545
Elem: &schema.Schema{Type: schema.TypeString},
4646
},
47+
48+
"workspace_names": {
49+
Type: schema.TypeSet,
50+
Optional: true,
51+
Computed: true,
52+
Elem: &schema.Schema{Type: schema.TypeString},
53+
},
4754
},
4855
}
4956
}
@@ -76,7 +83,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta
7683
ProjectID: proj.ID,
7784
}
7885
var workspaces []interface{}
79-
86+
var workspaceNames []interface{}
8087
for {
8188
wl, err := config.Client.Workspaces.List(ctx, orgName, readOptions)
8289
if err != nil {
@@ -85,6 +92,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta
8592

8693
for _, workspace := range wl.Items {
8794
workspaces = append(workspaces, workspace.ID)
95+
workspaceNames = append(workspaceNames, workspace.Name)
8896
}
8997

9098
// Exit the loop when we've seen all pages.
@@ -97,6 +105,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta
97105
}
98106

99107
d.Set("workspace_ids", workspaces)
108+
d.Set("workspace_names", workspaceNames)
100109
d.Set("description", proj.Description)
101110
d.SetId(proj.ID)
102111
return nil

internal/provider/data_source_project_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ func TestAccTFEProjectDataSource_basic(t *testing.T) {
3232
resource.TestCheckResourceAttrSet("data.tfe_project.foobar", "id"),
3333
resource.TestCheckResourceAttr(
3434
"data.tfe_project.foobar", "workspace_ids.#", "1"),
35+
resource.TestCheckResourceAttr(
36+
"data.tfe_project.foobar", "workspace_names.#", "1"),
3537
),
3638
},
3739
},

website/docs/d/project.html.markdown

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ Get information on a Project.
99

1010
Use this data source to get information about a project.
1111

12+
~> **NOTE:** The `workspace_ids` and `workspace_names` attributes are not guaranteed to return values in the same order, so they cannot be reliably mapped to one another. To map workspace names to IDs reliably, it is recommended to pass those names into the `tfe_workspace_ids` data source.
13+
1214
## Example Usage
1315

1416
```hcl
@@ -30,4 +32,5 @@ The following arguments are supported:
3032
In addition to all arguments above, the following attributes are exported:
3133

3234
* `id` - The project ID.
33-
* `workspace_ids` - IDs of the workspaces that are associated with the project.
35+
* `workspace_ids` - IDs of the workspaces that are associated with the project.
36+
* `workspace_names` - Names of the workspaces that are associated with the project.

0 commit comments

Comments
 (0)