From add764820a7651cb03fbd6216cfda39f6aba9857 Mon Sep 17 00:00:00 2001 From: Kyle George Date: Wed, 1 May 2024 14:11:59 -0400 Subject: [PATCH] Fix for default_tags and tags on EC2 block devices `default_tags` support for EC2 root block devices was introduced in hasicorp/terraform-provider-aws#33769, which is great ... except it makes the mix of `default_tags` and `tags` on a `root_block_device` perpetually showing drift even when there is none. The solution is to not remove the default tags config from the volume tags in ec2_instance. This diff fixes hashicorp/terraform-provider-aws#36448 for us in our environment (which references hashicorp/terraform-provider-aws#33769 as the change that introduced this bug). This diff possibly fixes hashicorp/terraform-provider-aws#36706 too, but we weren't hitting this issue. --- internal/service/ec2/ec2_instance.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/internal/service/ec2/ec2_instance.go b/internal/service/ec2/ec2_instance.go index 1ededbaf2eb3..31c81d5a6a34 100644 --- a/internal/service/ec2/ec2_instance.go +++ b/internal/service/ec2/ec2_instance.go @@ -1326,11 +1326,10 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", d.Id(), err) } - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig tags := KeyValueTags(ctx, volumeTags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - if err := d.Set("volume_tags", tags.RemoveDefaultConfig(defaultTagsConfig).Map()); err != nil { + if err := d.Set("volume_tags", tags.Map()); err != nil { return sdkdiag.AppendErrorf(diags, "setting volume_tags: %s", err) } } @@ -2320,7 +2319,6 @@ func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, m return nil, err } - defaultTagsConfig := meta.(*conns.AWSClient).DefaultTagsConfig ignoreTagsConfig := meta.(*conns.AWSClient).IgnoreTagsConfig for _, vol := range volResp.Volumes { @@ -2358,7 +2356,7 @@ func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, m bd[names.AttrTags] = KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map() } else { tags := KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) - bd[names.AttrTags] = tags.RemoveDefaultConfig(defaultTagsConfig).Map() + bd[names.AttrTags] = tags.Map() bd[names.AttrTagsAll] = tags.Map() } }