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

Expose the default tags configured on a provider as a data source #19391

Merged
merged 12 commits into from
May 21, 2021
Merged

Expose the default tags configured on a provider as a data source #19391

merged 12 commits into from
May 21, 2021

Conversation

wjam
Copy link
Contributor

@wjam wjam commented May 15, 2021

Allow the provider default_tags to be exposed as a data source so that the tags can be added to other areas where they are not automatically applied, like the volume_tags of a aws_instance or the tag_specifications of a aws_launch_template.

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for pull request followers and do not help prioritize the request

Relates OR Closes #19370

Output from acceptance testing:

$ make testacc TESTARGS='-run=TestAccAWSDefaultTagsDataSource_basic'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -count 1 -parallel 20 -run=TestAccAWSDefaultTagsDataSource_basic -timeout 180m
=== RUN   TestAccAWSDefaultTagsDataSource_basic
=== PAUSE TestAccAWSDefaultTagsDataSource_basic
=== CONT  TestAccAWSDefaultTagsDataSource_basic
--- PASS: TestAccAWSDefaultTagsDataSource_basic (5.99s)
PASS
ok      github.com/terraform-providers/terraform-provider-aws/aws       7.710s

@wjam wjam requested a review from a team as a code owner May 15, 2021 15:42
@ghost ghost added size/M Managed by automation to categorize the size of a PR. documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. labels May 15, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label May 15, 2021
@YakDriver YakDriver self-assigned this May 21, 2021
@YakDriver YakDriver removed the needs-triage Waiting for first response or review from a maintainer. label May 21, 2021
@ghost ghost added size/L Managed by automation to categorize the size of a PR. and removed size/M Managed by automation to categorize the size of a PR. labels May 21, 2021
Copy link
Member

@YakDriver YakDriver left a comment

Choose a reason for hiding this comment

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

Looks good! 🎉

Output from acceptance tests (us-west-2):

--- PASS: TestAccAWSDefaultTagsDataSource_empty (7.01s)
--- PASS: TestAccAWSDefaultTagsDataSource_multiple (7.03s)
--- PASS: TestAccAWSDefaultTagsDataSource_basic (7.03s)

Output from acceptance tests (GovCloud):

--- PASS: TestAccAWSDefaultTagsDataSource_multiple (6.15s)
--- PASS: TestAccAWSDefaultTagsDataSource_empty (6.23s)
--- PASS: TestAccAWSDefaultTagsDataSource_basic (6.25s)

@YakDriver YakDriver added this to the v3.43.0 milestone May 21, 2021
Steps: []resource.TestStep{
{
Config: composeConfig(
testAccAWSProviderConfigDefaultTags_Tags2("nuera", "hijo", "escalofrios", "calambres"),
Copy link
Contributor

Choose a reason for hiding this comment

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

escalofriante 😉

Comment on lines 21 to 27
if defaultTagsConfig == nil || defaultTagsConfig.Tags == nil {
return nil
}

if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil {
return err
}
Copy link
Contributor

@anGie44 anGie44 May 21, 2021

Choose a reason for hiding this comment

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

i'm not 100% on how we set empty values, but we could also always set the "tags" field if we do something like

tags := defaultTagsConfig.GetTags()

...

if len(tags) > 0 {
    tags = tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig)
}

if err := d.Set("tags", tags.Map()); err != nil {		
    return fmt.Errorf("error setting tags: %w", err)
}

Copy link
Member

Choose a reason for hiding this comment

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

only trouble with that is semgrep doesn't like it - ignore must accompany d.Set("tags"...)

wjam and others added 11 commits May 21, 2021 16:38
Allow the provider `default_tags` to be exposed as a data source so that the tags can be added to other areas where they are not automatically applied, like the `volume_tags` of a `aws_instance` or the `tag_specifications` of a `aws_launch_template`.

Closes #19370
* Fix documentation indentation
* Fix test naming
* Include `IgnoreConfig` in tags
Ignore AWS tags that may have been set in the providers default tags
@YakDriver
Copy link
Member

Acceptance tests are still happy:

--- PASS: TestAccAWSDefaultTagsDataSource_multiple (5.65s)
--- PASS: TestAccAWSDefaultTagsDataSource_basic (5.72s)
--- PASS: TestAccAWSDefaultTagsDataSource_empty (5.74s)
--- PASS: TestAccAWSDefaultTagsDataSource_ignore (11.45s)

@YakDriver YakDriver merged commit 4ed718a into hashicorp:main May 21, 2021
@wjam wjam deleted the default_tag_data_source branch May 22, 2021 08:49
@ghost
Copy link

ghost commented Jun 1, 2021

This has been released in version 3.43.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@github-actions
Copy link

github-actions bot commented Jul 2, 2021

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 2, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. provider Pertains to the provider itself, rather than any interaction with AWS. size/L Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Expose default tags as a datasource
3 participants