Skip to content

Commit

Permalink
ec2/instance: Remove tags_all from ds
Browse files Browse the repository at this point in the history
  • Loading branch information
YakDriver committed Mar 1, 2024
1 parent b78e6f9 commit 2cca02c
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
18 changes: 11 additions & 7 deletions internal/service/ec2/ec2_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -1319,7 +1319,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", d.Id(), err)
}

if err := readBlockDevices(ctx, d, meta, instance); err != nil {
if err := readBlockDevices(ctx, d, meta, instance, false); err != nil {
return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", d.Id(), err)
}

Expand Down Expand Up @@ -2161,8 +2161,8 @@ func modifyInstanceAttributeWithStopStart(ctx context.Context, conn *ec2.EC2, in
return nil
}

func readBlockDevices(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance) error {
ibds, err := readBlockDevicesFromInstance(ctx, d, meta, instance)
func readBlockDevices(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance, ds bool) error {
ibds, err := readBlockDevicesFromInstance(ctx, d, meta, instance, ds)
if err != nil {
return fmt.Errorf("reading block devices: %w", err)
}
Expand Down Expand Up @@ -2213,7 +2213,7 @@ func readBlockDevices(ctx context.Context, d *schema.ResourceData, meta interfac
return nil
}

func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance) (map[string]interface{}, error) {
func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance, ds bool) (map[string]interface{}, error) {
blockDevices := make(map[string]interface{})
blockDevices["ebs"] = make([]map[string]interface{}, 0)
blockDevices["root"] = nil
Expand Down Expand Up @@ -2279,9 +2279,13 @@ func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, m
bd["device_name"] = aws.StringValue(instanceBd.DeviceName)
}
if v, ok := d.GetOk("volume_tags"); !ok || v == nil || len(v.(map[string]interface{})) == 0 {
tags := KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)
bd[names.AttrTags] = tags.RemoveDefaultConfig(defaultTagsConfig).Map()
bd[names.AttrTagsAll] = tags.Map()
if ds {
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.AttrTagsAll] = tags.Map()
}
}

if blockDeviceIsRoot(instanceBd, instance) {
Expand Down
8 changes: 3 additions & 5 deletions internal/service/ec2/ec2_instance_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,7 @@ func DataSourceInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchemaComputed(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchemaComputed(),
"throughput": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -334,8 +333,7 @@ func DataSourceInstance() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},
names.AttrTags: tftags.TagsSchemaComputed(),
names.AttrTagsAll: tftags.TagsSchemaComputed(),
names.AttrTags: tftags.TagsSchemaComputed(),
"throughput": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -552,7 +550,7 @@ func instanceDescriptionAttributes(ctx context.Context, d *schema.ResourceData,
}

// Block devices
if err := readBlockDevices(ctx, d, meta, instance); err != nil {
if err := readBlockDevices(ctx, d, meta, instance, true); err != nil {
return fmt.Errorf("reading EC2 Instance (%s): %w", aws.StringValue(instance.InstanceId), err)
}
if _, ok := d.GetOk("ephemeral_block_device"); !ok {
Expand Down
2 changes: 1 addition & 1 deletion internal/service/ec2/ec2_spot_instance_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ func readInstance(ctx context.Context, d *schema.ResourceData, meta interface{})
"host": *instance.PrivateIpAddress,
})
}
if err := readBlockDevices(ctx, d, meta, instance); err != nil {
if err := readBlockDevices(ctx, d, meta, instance, false); err != nil {
return sdkdiag.AppendFromErr(diags, err)
}

Expand Down

0 comments on commit 2cca02c

Please sign in to comment.