Skip to content

Commit

Permalink
Fix for default_tags and tags on EC2 block devices
Browse files Browse the repository at this point in the history
`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 #36448 for us in our
environment (which references #33769 as
the change that introduced this bug).

This diff possibly fixes #36706 too, but
we weren't hitting this issue.
  • Loading branch information
Kyle George authored and YakDriver committed Oct 7, 2024
1 parent b37f55f commit 323e790
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1331,11 +1331,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)
}
}
Expand Down Expand Up @@ -2319,7 +2318,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 {
Expand Down Expand Up @@ -2357,7 +2355,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()
}
}
Expand Down

0 comments on commit 323e790

Please sign in to comment.