Skip to content

Commit 36f68db

Browse files
authored
Merge pull request #36054 from hashicorp/b-ec2-instance-ds-regression
ec2/instance: Fix data source regression
2 parents e6f3778 + 629395e commit 36f68db

File tree

4 files changed

+19
-11
lines changed

4 files changed

+19
-11
lines changed

.changelog/36054.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:bug
2+
data-source/aws_instance: Fix `panic: Invalid address to set` related to `root_block_device.0.tags_all`
3+
```

internal/service/ec2/ec2_instance.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,7 @@ func resourceInstanceRead(ctx context.Context, d *schema.ResourceData, meta inte
13191319
return sdkdiag.AppendErrorf(diags, "reading EC2 Instance (%s): %s", d.Id(), err)
13201320
}
13211321

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

@@ -2161,8 +2161,8 @@ func modifyInstanceAttributeWithStopStart(ctx context.Context, conn *ec2.EC2, in
21612161
return nil
21622162
}
21632163

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

2216-
func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance) (map[string]interface{}, error) {
2216+
func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, meta interface{}, instance *ec2.Instance, ds bool) (map[string]interface{}, error) {
22172217
blockDevices := make(map[string]interface{})
22182218
blockDevices["ebs"] = make([]map[string]interface{}, 0)
22192219
blockDevices["root"] = nil
@@ -2279,9 +2279,13 @@ func readBlockDevicesFromInstance(ctx context.Context, d *schema.ResourceData, m
22792279
bd["device_name"] = aws.StringValue(instanceBd.DeviceName)
22802280
}
22812281
if v, ok := d.GetOk("volume_tags"); !ok || v == nil || len(v.(map[string]interface{})) == 0 {
2282-
tags := KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)
2283-
bd[names.AttrTags] = tags.RemoveDefaultConfig(defaultTagsConfig).Map()
2284-
bd[names.AttrTagsAll] = tags.Map()
2282+
if ds {
2283+
bd[names.AttrTags] = KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig).Map()
2284+
} else {
2285+
tags := KeyValueTags(ctx, vol.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig)
2286+
bd[names.AttrTags] = tags.RemoveDefaultConfig(defaultTagsConfig).Map()
2287+
bd[names.AttrTagsAll] = tags.Map()
2288+
}
22852289
}
22862290

22872291
if blockDeviceIsRoot(instanceBd, instance) {

internal/service/ec2/ec2_instance_data_source.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag"
2222
tftags "github.com/hashicorp/terraform-provider-aws/internal/tags"
2323
"github.com/hashicorp/terraform-provider-aws/internal/tfresource"
24+
"github.com/hashicorp/terraform-provider-aws/names"
2425
)
2526

2627
// @SDKDataSource("aws_instance")
@@ -98,7 +99,7 @@ func DataSourceInstance() *schema.Resource {
9899
Type: schema.TypeString,
99100
Computed: true,
100101
},
101-
"tags": tftags.TagsSchemaComputed(),
102+
names.AttrTags: tftags.TagsSchemaComputed(),
102103
"throughput": {
103104
Type: schema.TypeInt,
104105
Computed: true,
@@ -332,7 +333,7 @@ func DataSourceInstance() *schema.Resource {
332333
Type: schema.TypeString,
333334
Computed: true,
334335
},
335-
"tags": tftags.TagsSchemaComputed(),
336+
names.AttrTags: tftags.TagsSchemaComputed(),
336337
"throughput": {
337338
Type: schema.TypeInt,
338339
Computed: true,
@@ -549,7 +550,7 @@ func instanceDescriptionAttributes(ctx context.Context, d *schema.ResourceData,
549550
}
550551

551552
// Block devices
552-
if err := readBlockDevices(ctx, d, meta, instance); err != nil {
553+
if err := readBlockDevices(ctx, d, meta, instance, true); err != nil {
553554
return fmt.Errorf("reading EC2 Instance (%s): %w", aws.StringValue(instance.InstanceId), err)
554555
}
555556
if _, ok := d.GetOk("ephemeral_block_device"); !ok {

internal/service/ec2/ec2_spot_instance_request.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func readInstance(ctx context.Context, d *schema.ResourceData, meta interface{})
317317
"host": *instance.PrivateIpAddress,
318318
})
319319
}
320-
if err := readBlockDevices(ctx, d, meta, instance); err != nil {
320+
if err := readBlockDevices(ctx, d, meta, instance, false); err != nil {
321321
return sdkdiag.AppendFromErr(diags, err)
322322
}
323323

0 commit comments

Comments
 (0)