Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for the resource_count attribute on tfe_workspace #682

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
## Unreleased


FEATURES:
* r/tfe_workspace: Add attribute `resource_count` to `tfe_workspace` ([#682](https://github.com/hashicorp/terraform-provider-tfe/pull/682))
* d/tfe_outputs: Add `nonsensitive_values` attribute to expose current non-sensitive outputs of a given workspace ([#711](https://github.com/hashicorp/terraform-provider-tfe/pull/711))

## v0.40.0 (December 6, 2022)
Expand Down
5 changes: 5 additions & 0 deletions tfe/resource_tfe_workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,10 @@ func resourceTFEWorkspace() *schema.Resource {
Optional: true,
Default: false,
},
"resource_count": {
Type: schema.TypeInt,
Computed: true,
},
},
}
}
Expand Down Expand Up @@ -406,6 +410,7 @@ func resourceTFEWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
d.Set("trigger_patterns", workspace.TriggerPatterns)
d.Set("working_directory", workspace.WorkingDirectory)
d.Set("organization", workspace.Organization.Name)
d.Set("resource_count", workspace.ResourceCount)

// Project will be nil for versions of TFE that predate projects
if workspace.Project != nil {
Expand Down
6 changes: 6 additions & 0 deletions tfe/resource_tfe_workspace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ func TestAccTFEWorkspace_basic(t *testing.T) {
"tfe_workspace.foobar", "trigger_prefixes.#", "0"),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "working_directory", ""),
resource.TestCheckResourceAttr(
"tfe_workspace.foobar", "resource_count", "0"),
),
},
},
Expand Down Expand Up @@ -2182,6 +2184,10 @@ func testAccCheckTFEWorkspaceAttributes(
return fmt.Errorf("Bad trigger prefixes: %s", workspace.TriggerPrefixes)
}

if workspace.ResourceCount >= 0 {
return fmt.Errorf("Bad resource count: %d", workspace.ResourceCount)
}

return nil
}
}
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ The `vcs_repo` block supports:
In addition to all arguments above, the following attributes are exported:

* `id` - The workspace ID.
* `resource_count` - The number of resources managed by the workspace.

## Import

Expand Down