From fc3412aa010fabada62222bb0b3e081e4cf43d87 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 11:38:52 -0500 Subject: [PATCH 1/6] ec2/instance: Fix data source regression, crash --- internal/service/ec2/ec2_instance_data_source.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/internal/service/ec2/ec2_instance_data_source.go b/internal/service/ec2/ec2_instance_data_source.go index ecc11abd043..470843c9629 100644 --- a/internal/service/ec2/ec2_instance_data_source.go +++ b/internal/service/ec2/ec2_instance_data_source.go @@ -21,6 +21,7 @@ import ( "github.com/hashicorp/terraform-provider-aws/internal/errs/sdkdiag" tftags "github.com/hashicorp/terraform-provider-aws/internal/tags" "github.com/hashicorp/terraform-provider-aws/internal/tfresource" + "github.com/hashicorp/terraform-provider-aws/names" ) // @SDKDataSource("aws_instance") @@ -98,7 +99,8 @@ func DataSourceInstance() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchemaComputed(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "throughput": { Type: schema.TypeInt, Computed: true, @@ -332,7 +334,8 @@ func DataSourceInstance() *schema.Resource { Type: schema.TypeString, Computed: true, }, - "tags": tftags.TagsSchemaComputed(), + names.AttrTags: tftags.TagsSchemaComputed(), + names.AttrTagsAll: tftags.TagsSchemaComputed(), "throughput": { Type: schema.TypeInt, Computed: true, From b4d03fcc13deea2bd53cac112cf90e71724aba31 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 11:41:04 -0500 Subject: [PATCH 2/6] Add changelog --- .changelog/36054.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/36054.txt diff --git a/.changelog/36054.txt b/.changelog/36054.txt new file mode 100644 index 00000000000..1b59cf294d5 --- /dev/null +++ b/.changelog/36054.txt @@ -0,0 +1,3 @@ +```release-note:bug +data-source/aws_instance: Fix `panic: Invalid address to set` for `root_block_device.0.tags_all` +``` \ No newline at end of file From e684ac7c65de82a9d659f8705d08cd19d7b600d6 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 11:45:39 -0500 Subject: [PATCH 3/6] Update changelog --- .changelog/36054.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/36054.txt b/.changelog/36054.txt index 1b59cf294d5..118f337e0e9 100644 --- a/.changelog/36054.txt +++ b/.changelog/36054.txt @@ -1,3 +1,3 @@ ```release-note:bug -data-source/aws_instance: Fix `panic: Invalid address to set` for `root_block_device.0.tags_all` +data-source/aws_instance: Add `root_block_device.0.tags_all` and `ebs_block_device.*.tags_all` to fix `panic: Invalid address to set` for `root_block_device.0.tags_all` ``` \ No newline at end of file From b78e6f993deb992f9c08044ecc66994cae09a3c4 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 11:46:20 -0500 Subject: [PATCH 4/6] Update changelog --- .changelog/36054.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/36054.txt b/.changelog/36054.txt index 118f337e0e9..58fd22ddd9a 100644 --- a/.changelog/36054.txt +++ b/.changelog/36054.txt @@ -1,3 +1,3 @@ ```release-note:bug -data-source/aws_instance: Add `root_block_device.0.tags_all` and `ebs_block_device.*.tags_all` to fix `panic: Invalid address to set` for `root_block_device.0.tags_all` +data-source/aws_instance: Add `root_block_device.0.tags_all` and `ebs_block_device.*.tags_all` to fix `panic: Invalid address to set` ``` \ No newline at end of file From 2cca02cd6bc0384aab49b5284483c60d9cd0fdfc Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 12:11:22 -0500 Subject: [PATCH 5/6] ec2/instance: Remove tags_all from ds --- internal/service/ec2/ec2_instance.go | 18 +++++++++++------- .../service/ec2/ec2_instance_data_source.go | 8 +++----- .../service/ec2/ec2_spot_instance_request.go | 2 +- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/internal/service/ec2/ec2_instance.go b/internal/service/ec2/ec2_instance.go index cd9db6f5f8a..e2e5a1b4992 100644 --- a/internal/service/ec2/ec2_instance.go +++ b/internal/service/ec2/ec2_instance.go @@ -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) } @@ -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) } @@ -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 @@ -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) { diff --git a/internal/service/ec2/ec2_instance_data_source.go b/internal/service/ec2/ec2_instance_data_source.go index 470843c9629..09733231d14 100644 --- a/internal/service/ec2/ec2_instance_data_source.go +++ b/internal/service/ec2/ec2_instance_data_source.go @@ -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, @@ -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, @@ -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 { diff --git a/internal/service/ec2/ec2_spot_instance_request.go b/internal/service/ec2/ec2_spot_instance_request.go index 0cb13a8c114..f8226a6e1ce 100644 --- a/internal/service/ec2/ec2_spot_instance_request.go +++ b/internal/service/ec2/ec2_spot_instance_request.go @@ -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) } From 629395ece4157a28c74bb478af7d8b7d99bd5843 Mon Sep 17 00:00:00 2001 From: Dirk Avery Date: Fri, 1 Mar 2024 12:16:27 -0500 Subject: [PATCH 6/6] Fix changelog --- .changelog/36054.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/36054.txt b/.changelog/36054.txt index 58fd22ddd9a..ae151ddcdf1 100644 --- a/.changelog/36054.txt +++ b/.changelog/36054.txt @@ -1,3 +1,3 @@ ```release-note:bug -data-source/aws_instance: Add `root_block_device.0.tags_all` and `ebs_block_device.*.tags_all` to fix `panic: Invalid address to set` +data-source/aws_instance: Fix `panic: Invalid address to set` related to `root_block_device.0.tags_all` ``` \ No newline at end of file