-
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
[Proof of Concept] Default tags implementation: provider and subnet/vpc resources #17974
Conversation
750191d
to
82242d3
Compare
82242d3
to
7d85dac
Compare
Pending some potential changes noted over in #17941 (review) |
return fmt.Errorf(`"tags" are identical to those in the "default_tags" configuration block of the provider: please de-duplicate and try again`) | ||
} | ||
|
||
allTags := defaultTagsConfig.MergeTags(resourceTags).IgnoreConfig(ignoreTagsConfig) |
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.
to accommodate cases where both (default and ignore are configured). do you think this is a valid use case @bflad ? related tests are in each resource's test file with the suffix defaultAndIgnoreTags
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 think configuring both is certainly valid as long as the tag keys do not overlap. For example, if I'm working in engineering and running Kubernetes I may want to do something like:
provider "aws" {
default_tags {
tags = {
CostCenter = "Engineering"
}
}
ignore_tags {
key_prefixes = ["kubernetes.io/"]
}
}
Maybe we should error in the overlapping keys case, if we do not already. Does not need to be in the initial pull request though. 😄
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.
This looks really good, I'm stepping into a meeting for an hour, but all I have left to do is run the testing at this point to verify. 👍
@@ -4,6 +4,254 @@ import ( | |||
"testing" | |||
) | |||
|
|||
func TestKeyValueTagsDefaultConfigMergeTags(t *testing.T) { | |||
testCases := []struct { |
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.
Nice!
if err := d.Set("tags", keyvaluetags.Ec2KeyValueTags(subnet.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig).Map()); err != nil { | ||
tags := keyvaluetags.Ec2KeyValueTags(subnet.Tags).IgnoreAws().IgnoreConfig(ignoreTagsConfig) | ||
|
||
//lintignore:AWSR002 |
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.
We can figure out how to adjust this linter after this pull request, even if that means creating a separate function to bundle this code up -- I personally really like the split here so tags
and tags_all
values are straightforward to 👀 in the d.Set()
calls.
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.
sounds good! i'll make an in issue for it and follow-up 👍
}) | ||
} | ||
|
||
func TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag(t *testing.T) { |
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.
Love all these test cases
if defaultTagsConfig.TagsEqual(resourceTags) { | ||
return fmt.Errorf(`"tags" are identical to those in the "default_tags" configuration block of the provider: please de-duplicate and try again`) | ||
} |
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 think this is a good error to have when all tags are equivalent 👍
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.
Two nits on the changelog entries, otherwise this is a fantastic start. Great work. 🚀
Output from acceptance testing in AWS Commercial:
--- PASS: TestAccAWSProvider_AssumeRole_Empty (47.43s)
--- PASS: TestAccAWSProvider_DefaultAndIgnoreTags_EmptyConfigurationBlocks (23.95s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_Multiple (39.35s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_None (43.78s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_One (32.28s)
--- PASS: TestAccAWSProvider_Endpoints (40.52s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (30.92s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (38.83s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (31.18s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (32.62s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (39.85s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (35.49s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (36.41s)
--- PASS: TestAccAWSProvider_Region_AwsC2S (33.25s)
--- PASS: TestAccAWSProvider_Region_AwsChina (27.06s)
--- PASS: TestAccAWSProvider_Region_AwsCommercial (31.68s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (36.04s)
--- PASS: TestAccAWSProvider_Region_AwsSC2S (33.29s)
--- PASS: TestAccAWSSubnet_availabilityZoneId (62.10s)
--- PASS: TestAccAWSSubnet_basic (66.30s)
--- PASS: TestAccAWSSubnet_defaultAndIgnoreTags (172.35s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_duplicateTag (11.92s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_nonOverlappingTag (198.12s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag (197.36s)
--- PASS: TestAccAWSSubnet_defaultTags_providerOnly (185.18s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToProviderOnly (135.01s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToResourceOnly (136.87s)
--- PASS: TestAccAWSSubnet_disappears (71.35s)
--- PASS: TestAccAWSSubnet_enableIpv6 (123.25s)
--- PASS: TestAccAWSSubnet_ignoreTags (173.12s)
--- PASS: TestAccAWSSubnet_ipv6 (119.99s)
--- PASS: TestAccAWSSubnet_MapPublicIpOnLaunch (234.20s)
--- PASS: TestAccAWSSubnet_tags (140.78s)
--- SKIP: TestAccAWSSubnet_CustomerOwnedIpv4Pool (1.04s)
--- SKIP: TestAccAWSSubnet_MapCustomerOwnedIpOnLaunch (0.71s)
--- SKIP: TestAccAWSSubnet_outpost (1.02s)
--- PASS: TestAccAWSVpc_AssignGeneratedIpv6CidrBlock (161.38s)
--- PASS: TestAccAWSVpc_basic (84.09s)
--- PASS: TestAccAWSVpc_bothDnsOptionsSet (103.70s)
--- PASS: TestAccAWSVpc_classiclinkDnsSupportOptionSet (90.72s)
--- PASS: TestAccAWSVpc_classiclinkOptionSet (89.79s)
--- PASS: TestAccAWSVpc_coreMismatchedDiffs (73.00s)
--- PASS: TestAccAWSVpc_defaultAndIgnoreTags (84.82s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_duplicateTag (11.01s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_nonOverlappingTag (187.70s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_overlappingTag (88.86s)
--- PASS: TestAccAWSVpc_defaultTags_providerOnly (155.12s)
--- PASS: TestAccAWSVpc_defaultTags_updateToProviderOnly (131.24s)
--- PASS: TestAccAWSVpc_defaultTags_updateToResourceOnly (131.38s)
--- PASS: TestAccAWSVpc_DisabledDnsSupport (101.98s)
--- PASS: TestAccAWSVpc_disappears (57.68s)
--- PASS: TestAccAWSVpc_ignoreTags (93.11s)
--- PASS: TestAccAWSVpc_tags (211.03s)
--- PASS: TestAccAWSVpc_Tenancy (161.25s)
--- PASS: TestAccAWSVpc_update (150.61s)
Output from acceptance testing in AWS GovCloud (US):
--- PASS: TestAccAWSProvider_AssumeRole_Empty (54.05s)
--- PASS: TestAccAWSProvider_DefaultAndIgnoreTags_EmptyConfigurationBlocks (43.18s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_Multiple (32.95s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_None (21.45s)
--- PASS: TestAccAWSProvider_DefaultTags_Tags_One (37.71s)
--- PASS: TestAccAWSProvider_Endpoints (40.39s)
--- PASS: TestAccAWSProvider_IgnoreTags_EmptyConfigurationBlock (38.03s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_Multiple (31.33s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_None (32.15s)
--- PASS: TestAccAWSProvider_IgnoreTags_KeyPrefixes_One (35.19s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_Multiple (40.27s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_None (32.84s)
--- PASS: TestAccAWSProvider_IgnoreTags_Keys_One (42.61s)
--- PASS: TestAccAWSProvider_Region_AwsC2S (31.91s)
--- PASS: TestAccAWSProvider_Region_AwsChina (27.52s)
--- PASS: TestAccAWSProvider_Region_AwsCommercial (18.89s)
--- PASS: TestAccAWSProvider_Region_AwsGovCloudUs (20.20s)
--- PASS: TestAccAWSProvider_Region_AwsSC2S (19.41s)
--- PASS: TestAccAWSSubnet_availabilityZoneId (53.68s)
--- PASS: TestAccAWSSubnet_basic (103.10s)
--- PASS: TestAccAWSSubnet_defaultAndIgnoreTags (174.14s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_duplicateTag (14.71s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_nonOverlappingTag (172.37s)
--- PASS: TestAccAWSSubnet_defaultTags_providerAndResource_overlappingTag (180.57s)
--- PASS: TestAccAWSSubnet_defaultTags_providerOnly (181.37s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToProviderOnly (135.37s)
--- PASS: TestAccAWSSubnet_defaultTags_updateToResourceOnly (140.56s)
--- PASS: TestAccAWSSubnet_disappears (77.51s)
--- PASS: TestAccAWSSubnet_enableIpv6 (128.65s)
--- PASS: TestAccAWSSubnet_ignoreTags (176.63s)
--- PASS: TestAccAWSSubnet_ipv6 (121.96s)
--- PASS: TestAccAWSSubnet_MapPublicIpOnLaunch (179.33s)
--- PASS: TestAccAWSSubnet_tags (245.77s)
--- SKIP: TestAccAWSSubnet_CustomerOwnedIpv4Pool (1.99s)
--- SKIP: TestAccAWSSubnet_MapCustomerOwnedIpOnLaunch (0.81s)
--- SKIP: TestAccAWSSubnet_outpost (2.42s)
--- FAIL: TestAccAWSVpc_classiclinkDnsSupportOptionSet (34.06s) # https://github.com/hashicorp/terraform-provider-aws/issues/17460
--- FAIL: TestAccAWSVpc_classiclinkOptionSet (35.36s) # https://github.com/hashicorp/terraform-provider-aws/issues/17460
--- PASS: TestAccAWSVpc_AssignGeneratedIpv6CidrBlock (212.69s)
--- PASS: TestAccAWSVpc_basic (83.60s)
--- PASS: TestAccAWSVpc_bothDnsOptionsSet (99.42s)
--- PASS: TestAccAWSVpc_coreMismatchedDiffs (75.31s)
--- PASS: TestAccAWSVpc_defaultAndIgnoreTags (163.31s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_duplicateTag (6.40s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_nonOverlappingTag (175.66s)
--- PASS: TestAccAWSVpc_defaultTags_providerAndResource_overlappingTag (172.40s)
--- PASS: TestAccAWSVpc_defaultTags_providerOnly (146.26s)
--- PASS: TestAccAWSVpc_defaultTags_updateToProviderOnly (108.09s)
--- PASS: TestAccAWSVpc_defaultTags_updateToResourceOnly (115.28s)
--- PASS: TestAccAWSVpc_DisabledDnsSupport (100.36s)
--- PASS: TestAccAWSVpc_disappears (57.28s)
--- PASS: TestAccAWSVpc_ignoreTags (154.45s)
--- PASS: TestAccAWSVpc_tags (206.08s)
--- PASS: TestAccAWSVpc_Tenancy (214.24s)
--- PASS: TestAccAWSVpc_update (151.29s)
Co-authored-by: Brian Flad <bflad417@gmail.com>
Co-authored-by: Brian Flad <bflad417@gmail.com>
This has been released in version 3.33.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 issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Closes #17826
Closes #17827
Output from acceptance testing: