diff --git a/CHANGELOG.md b/CHANGELOG.md index 9b38403e4..bc98e3de0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ## Unreleased +ENHANCEMENTS: +* `d/tfe_project`: Add `workspace_names` attribute, by @1natedawg [#1429](https://github.com/hashicorp/terraform-provider-tfe/pull/1429) + BUG FIXES: * `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) diff --git a/internal/provider/data_source_project.go b/internal/provider/data_source_project.go index 07a1c9b1d..c91e7571c 100644 --- a/internal/provider/data_source_project.go +++ b/internal/provider/data_source_project.go @@ -44,6 +44,13 @@ func dataSourceTFEProject() *schema.Resource { Computed: true, Elem: &schema.Schema{Type: schema.TypeString}, }, + + "workspace_names": { + Type: schema.TypeSet, + Optional: true, + Computed: true, + Elem: &schema.Schema{Type: schema.TypeString}, + }, }, } } @@ -76,7 +83,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta ProjectID: proj.ID, } var workspaces []interface{} - + var workspaceNames []interface{} for { wl, err := config.Client.Workspaces.List(ctx, orgName, readOptions) if err != nil { @@ -85,6 +92,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta for _, workspace := range wl.Items { workspaces = append(workspaces, workspace.ID) + workspaceNames = append(workspaceNames, workspace.Name) } // Exit the loop when we've seen all pages. @@ -97,6 +105,7 @@ func dataSourceTFEProjectRead(ctx context.Context, d *schema.ResourceData, meta } d.Set("workspace_ids", workspaces) + d.Set("workspace_names", workspaceNames) d.Set("description", proj.Description) d.SetId(proj.ID) return nil diff --git a/internal/provider/data_source_project_test.go b/internal/provider/data_source_project_test.go index 0af8c0bb6..529dcd5e2 100644 --- a/internal/provider/data_source_project_test.go +++ b/internal/provider/data_source_project_test.go @@ -32,6 +32,8 @@ func TestAccTFEProjectDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrSet("data.tfe_project.foobar", "id"), resource.TestCheckResourceAttr( "data.tfe_project.foobar", "workspace_ids.#", "1"), + resource.TestCheckResourceAttr( + "data.tfe_project.foobar", "workspace_names.#", "1"), ), }, }, diff --git a/website/docs/d/project.html.markdown b/website/docs/d/project.html.markdown index 8e36f5712..431d450f0 100644 --- a/website/docs/d/project.html.markdown +++ b/website/docs/d/project.html.markdown @@ -9,6 +9,8 @@ Get information on a Project. Use this data source to get information about a project. +~> **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. + ## Example Usage ```hcl @@ -30,4 +32,5 @@ The following arguments are supported: In addition to all arguments above, the following attributes are exported: * `id` - The project ID. -* `workspace_ids` - IDs of the workspaces that are associated with the project. \ No newline at end of file +* `workspace_ids` - IDs of the workspaces that are associated with the project. +* `workspace_names` - Names of the workspaces that are associated with the project.