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 hashicorp#36448 for us in our
environment (which references hashicorp#33769 as
the change that introduced this bug).

This diff possibly fixes hashicorp#36706 too, but
we weren't hitting this issue.
  • Loading branch information
Kyle George committed May 10, 2024
1 parent 121157e commit add7648
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 @@ -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)
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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()
}
}
Expand Down

0 comments on commit add7648

Please sign in to comment.