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

feat: Data source for workspace tags in an organization #773

Merged
merged 16 commits into from
Feb 9, 2023

Conversation

rhughes1
Copy link
Contributor

Description

This is a new data source is meant to retrieve all the workspace tags for a given organization. With this new data source, we can get the ID, name, and instance count for the organization.

Testing plan

  1. Create a Terraform Cloud/Enterprise organization
  2. Create a new workspace with tags (For example, foo and bar)
  3. Create another workspace with similar tags and different tags (For example, foo and test)
  4. Write the necessary Terraform configuration to pull down the tags for a given organization.
data "tfe_organization_workspace_tags" "example" {
  organization = "my-org-name"
}
  1. In the tags attribute, we should see something like
[
  {
    id = "tag-12345q"
    name = "foo"
    instance_count = "2"
  },
  {
    id = "tag-qwert12"
    name = "bar"
    instance_count = "1"
  },
  {
    id = "tag-qwe333rt12"
    name = "test"
    instance_count = "1"
  },
]

Doc Preview:

image

External links

@rhughes1 rhughes1 requested a review from a team as a code owner January 20, 2023 01:53
@uturunku1
Copy link
Collaborator

@rhughes1 Hi Ryan! Thank you for your valuable contribution. I have try out your changes, and so far they look good. One of my colleagues was suggesting that you rename one of the tag attributes. What do you think of changing instance_count to workspace_count? Maybe the word "instance" could be a little confusing in this context?

@rhughes1
Copy link
Contributor Author

I kept it to instance_count just to keep it aligned with the API. I can easily make the change if that's preferred?

@rhughes1
Copy link
Contributor Author

@uturunku1 I updated the instance_count to workspace_count as per your suggestion.

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I smoke tested this and it worked as expected. Let me know what you think! Thanks again

CHANGELOG.md Outdated Show resolved Hide resolved
tfe/provider.go Outdated Show resolved Hide resolved
tfe/data_source_organization_tags_test.go Outdated Show resolved Hide resolved
tfe/data_source_organization_tags.go Outdated Show resolved Hide resolved
tfe/data_source_organization_tags.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey, sorry for not getting feedback the last couple of days. We had some issues with our test infrastructure due to some internal tooling upgrades.

When I run your new test, I get the following error. Can you replicate this?

$ TESTARGS="-run TestAccTFEOrganizationTagsDataSource_basic" make testacc
TF_ACC=1 TF_LOG_SDK_PROTO=OFF go test $(go list ./... |grep -v 'vendor') -v -run TestAccTFEOrganizationTagsDataSource_basic -timeout 15m
?   	github.com/hashicorp/terraform-provider-tfe	[no test files]
=== RUN   TestAccTFEOrganizationTagsDataSource_basic
    data_source_organization_tags_test.go:16: Step 1/1 error: Check failed: 1 error occurred:
        	* Check 2/2 error: data.tfe_organization_tags.foobar: list or set attribute 'tags' must be checked by element count key (tags.#) or element value keys (e.g. tags.0). Set element value checks should use TestCheckTypeSet functions instead.

--- FAIL: TestAccTFEOrganizationTagsDataSource_basic (26.97s)
FAIL
FAIL	github.com/hashicorp/terraform-provider-tfe/tfe	27.304s
?   	github.com/hashicorp/terraform-provider-tfe/version	[no test files]
FAIL
make: *** [testacc] Error 1

@rhughes1
Copy link
Contributor Author

rhughes1 commented Feb 9, 2023

@brandonc I modified the tests so that it's specifically looking at the attributes being set within the tags attribute for more clarity. Do those changes make sense?

Copy link
Collaborator

@brandonc brandonc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thanks!

@brandonc brandonc merged commit 46d2314 into hashicorp:main Feb 9, 2023
@rhughes1 rhughes1 deleted the rhughes1-data-source-workspace-tags branch February 9, 2023 20:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants