Skip to content

Commit

Permalink
update markdown and changelog
Browse files Browse the repository at this point in the history
  • Loading branch information
Uk1288 committed Jul 8, 2022
1 parent bb32e3a commit 5e0f62a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -36,6 +36,7 @@ FEATURES:
* **New Data Source**: d/tfe_organization_run_task ([#488](https://github.com/hashicorp/terraform-provider-tfe/pull/488))
* **New Data Source**: d/tfe_workspace_run_task ([#488](https://github.com/hashicorp/terraform-provider-tfe/pull/488))
* r/tfe_notification_configuration: Add Microsoft Teams notification type ([#484](https://github.com/hashicorp/terraform-provider-tfe/pull/484))
* d/workspace_ids: Add `exclude_tags` to `tfe_workspace_ids` attributes ([#523](https://github.com/hashicorp/terraform-provider-tfe/pull/523))

## 0.31.0 (April 21, 2022)

Expand Down
14 changes: 11 additions & 3 deletions tfe/data_source_workspace_ids.go
Expand Up @@ -27,7 +27,7 @@ func dataSourceTFEWorkspaceIDs() *schema.Resource {
},

"exclude_tags": {
Type: schema.TypeList,
Type: schema.TypeSet,
Elem: &schema.Schema{Type: schema.TypeString},
Optional: true,
},
Expand Down Expand Up @@ -78,7 +78,7 @@ func dataSourceTFEWorkspaceIDsRead(d *schema.ResourceData, meta interface{}) err

excludeTagLookupMap := make(map[string]bool)
var excludeTagBuf strings.Builder
for _, excludedTag := range d.Get("exclude_tags").([]interface{}) {
for _, excludedTag := range d.Get("exclude_tags").(*schema.Set).List() {
if exTag, ok := excludedTag.(string); ok && len(strings.TrimSpace(exTag)) != 0 {
excludeTagLookupMap[exTag] = true

Expand Down Expand Up @@ -116,7 +116,15 @@ func dataSourceTFEWorkspaceIDsRead(d *schema.ResourceData, meta interface{}) err

for _, w := range wl.Items {
nameIncluded := isWildcard || names[w.Name]
if hasOnlyTags || nameIncluded {
// fallback for tfe instances that don't yet support exclude-tags
hasExcludedTag := false
for _, tag := range w.TagNames {
if _, ok := excludeTagLookupMap[tag]; ok {
hasExcludedTag = true
break
}
}
if (hasOnlyTags || nameIncluded) && !hasExcludedTag {
fullNames[w.Name] = organization + "/" + w.Name
ids[w.Name] = w.ID
}
Expand Down
8 changes: 4 additions & 4 deletions tfe/data_source_workspace_ids_test.go
Expand Up @@ -520,9 +520,9 @@ resource "tfe_workspace" "dummy" {
data "tfe_workspace_ids" "good" {
tag_names = ["good"]
exclude_tags = ["happy"]
exclude_tags = ["happy"]
organization = tfe_workspace.foo.organization
depends_on = [
depends_on = [
tfe_workspace.foo,
tfe_workspace.bar,
tfe_workspace.dummy
Expand Down Expand Up @@ -557,9 +557,9 @@ resource "tfe_workspace" "dummy" {
data "tfe_workspace_ids" "good" {
tag_names = ["good", "happy"]
exclude_tags = ["happy"]
exclude_tags = ["happy"]
organization = tfe_workspace.foo.organization
depends_on = [
depends_on = [
tfe_workspace.foo,
tfe_workspace.bar,
tfe_workspace.dummy
Expand Down
9 changes: 8 additions & 1 deletion website/docs/d/workspace_ids.html.markdown
Expand Up @@ -27,6 +27,12 @@ data "tfe_workspace_ids" "prod-apps" {
tag_names = ["prod", "app", "aws"]
organization = "my-org-name"
}
data "tfe_workspace_ids" "prod-only" {
tag_names = ["prod"]
exclude_tags = ["app"]
organization = "my-org-name"
}
```

## Argument Reference
Expand All @@ -39,11 +45,12 @@ The following arguments are supported. At least one of `names` or `tag_names` mu
To select _all_ workspaces for an organization, provide a list with a single
asterisk, like `["*"]`. No other use of wildcards is supported.
* `tag_names` - (Optional) A list of tag names to search for.
* `exclude_tags` - (Optional) A list of tag names to exclude when searching.
* `organization` - (Required) Name of the organization.

## Attributes Reference

In addition to all arguments above, the following attributes are exported:

* `full_names` - A map of workspace names and their full names, which look like `<ORGANIZATION>/<WORKSPACE>`.
* `full_names` - A map of workspace names and their full names, which look like `<ORGANIZATION>/<WORKSPACE>`.
* `ids` - A map of workspace names and their opaque, immutable IDs, which look like `ws-<RANDOM STRING>`.

0 comments on commit 5e0f62a

Please sign in to comment.