Skip to content

Commit

Permalink
Merge pull request #1429 from 1natedawg/main
Browse files Browse the repository at this point in the history
d/tfe_project: Output workspace names
  • Loading branch information
brandonc authored Aug 5, 2024
2 parents f88988b + 9b9580d commit 68c4a0e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
11 changes: 10 additions & 1 deletion internal/provider/data_source_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
},
},
}
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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.
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions internal/provider/data_source_project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
},
Expand Down
5 changes: 4 additions & 1 deletion website/docs/d/project.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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.
* `workspace_ids` - IDs of the workspaces that are associated with the project.
* `workspace_names` - Names of the workspaces that are associated with the project.

0 comments on commit 68c4a0e

Please sign in to comment.