-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Conversation
There was a problem hiding this 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)
Steps: []resource.TestStep{ | ||
{ | ||
Config: composeConfig( | ||
testAccAWSProviderConfigDefaultTags_Tags2("nuera", "hijo", "escalofrios", "calambres"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
escalofriante 😉
aws/data_source_aws_default_tags.go
Outdated
if defaultTagsConfig == nil || defaultTagsConfig.Tags == nil { | ||
return nil | ||
} | ||
|
||
if err := d.Set("tags", defaultTagsConfig.Tags.IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
return err | ||
} |
There was a problem hiding this comment.
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)
}
There was a problem hiding this comment.
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"...)
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
Acceptance tests are still happy:
|
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! |
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. |
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 thevolume_tags
of aaws_instance
or thetag_specifications
of aaws_launch_template
.Community Note
Relates OR Closes #19370
Output from acceptance testing: