From 27640e79ce3ba0868d1cf51bf7a544b10f7b5018 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Wed, 5 Jul 2023 19:00:40 -0400 Subject: [PATCH 1/5] add asset_id field to ec2_host --- internal/service/ec2/ec2_host.go | 11 ++++++ internal/service/ec2/ec2_host_test.go | 48 +++++++++++++++++++++++++++ website/docs/r/ec2_host.html.markdown | 1 + 3 files changed, 60 insertions(+) diff --git a/internal/service/ec2/ec2_host.go b/internal/service/ec2/ec2_host.go index 376bf493fc91..4b71dab74c44 100644 --- a/internal/service/ec2/ec2_host.go +++ b/internal/service/ec2/ec2_host.go @@ -44,6 +44,12 @@ func ResourceHost() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "asset_id": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + RequiredWith: []string{"outpost_arn"}, + }, "auto_placement": { Type: schema.TypeString, Optional: true, @@ -99,6 +105,10 @@ func resourceHostCreate(ctx context.Context, d *schema.ResourceData, meta interf TagSpecifications: getTagSpecificationsIn(ctx, ec2.ResourceTypeDedicatedHost), } + if v, ok := d.GetOk("asset_id"); ok { + input.AssetIds = []*string{aws.String(v.(string))} + } + if v, ok := d.GetOk("instance_family"); ok { input.InstanceFamily = aws.String(v.(string)) } @@ -150,6 +160,7 @@ func resourceHostRead(ctx context.Context, d *schema.ResourceData, meta interfac Resource: fmt.Sprintf("dedicated-host/%s", d.Id()), }.String() d.Set("arn", arn) + d.Set("asset_id", host.AssetId) d.Set("auto_placement", host.AutoPlacement) d.Set("availability_zone", host.AvailabilityZone) d.Set("host_recovery", host.HostRecovery) diff --git a/internal/service/ec2/ec2_host_test.go b/internal/service/ec2/ec2_host_test.go index 6ed0ac332f88..792cf1479710 100644 --- a/internal/service/ec2/ec2_host_test.go +++ b/internal/service/ec2/ec2_host_test.go @@ -170,6 +170,29 @@ func TestAccEC2Host_tags(t *testing.T) { }) } +func TestAccEC2Host_outpostAssetId(t *testing.T) { + ctx := acctest.Context(t) + var host ec2.Host + resourceName := "aws_ec2_host.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(ctx, t); acctest.PreCheckOutpostsOutposts(ctx, t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories, + CheckDestroy: testAccCheckHostDestroy(ctx), + Steps: []resource.TestStep{ + { + Config: testAccHostConfig_outpostAssetId(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckHostExists(ctx, resourceName, &host), + resource.TestCheckResourceAttrSet(resourceName, "asset_id"), + ), + }, + }, + }) +} + func TestAccEC2Host_outpost(t *testing.T) { ctx := acctest.Context(t) var host ec2.Host @@ -316,6 +339,31 @@ resource "aws_ec2_host" "test" { `, tagKey1, tagValue1, tagKey2, tagValue2)) } +func testAccHostConfig_outpostAssetId(rName string) string { + return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` +data "aws_outposts_outposts" "test" {} + +data "aws_outposts_outpost" "test" { + id = tolist(data.aws_outposts_outposts.test.ids)[0] +} + +data "aws_outposts_assets" "test" { + arn = data.aws_outposts_outpost.test.arn +} + +resource "aws_ec2_host" "test" { + asset_id = tolist(data.aws_outposts_assets.test.asset_ids)[3] + instance_family = "m5d" + availability_zone = data.aws_availability_zones.available.names[0] + outpost_arn = data.aws_outposts_outpost.test.arn + + tags = { + Name = %[1]q + } +} +`, rName)) +} + func testAccHostConfig_outpost(rName string) string { return acctest.ConfigCompose(acctest.ConfigAvailableAZsNoOptIn(), fmt.Sprintf(` data "aws_outposts_outposts" "test" {} diff --git a/website/docs/r/ec2_host.html.markdown b/website/docs/r/ec2_host.html.markdown index fff0822f5515..6c38192279c1 100644 --- a/website/docs/r/ec2_host.html.markdown +++ b/website/docs/r/ec2_host.html.markdown @@ -27,6 +27,7 @@ resource "aws_ec2_host" "test" { The following arguments are supported: +* `asset_id` - (Optional) The ID of the Outpost hardware asset on which to allocate the Dedicated Hosts. This parameter is supported only if you specify OutpostArn. If you are allocating the Dedicated Hosts in a Region, omit this parameter. * `auto_placement` - (Optional) Indicates whether the host accepts any untargeted instance launches that match its instance type configuration, or if it only accepts Host tenancy instance launches that specify its unique host ID. Valid values: `on`, `off`. Default: `on`. * `availability_zone` - (Required) The Availability Zone in which to allocate the Dedicated Host. * `host_recovery` - (Optional) Indicates whether to enable or disable host recovery for the Dedicated Host. Valid values: `on`, `off`. Default: `off`. From b4c5b786ae7db9d55e33688c431ca4d420f2b0af Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Wed, 5 Jul 2023 19:03:14 -0400 Subject: [PATCH 2/5] add changelog --- .changelog/32388.txt | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .changelog/32388.txt diff --git a/.changelog/32388.txt b/.changelog/32388.txt new file mode 100644 index 000000000000..0868df92dd2d --- /dev/null +++ b/.changelog/32388.txt @@ -0,0 +1,3 @@ +```release-note:enhancement +resource/ec2_host: Add `asset_id` argument +``` \ No newline at end of file From 99c71bd0d8c95293bb2659aaa8e07c0a56ccbff3 Mon Sep 17 00:00:00 2001 From: Albert Silva Date: Wed, 5 Jul 2023 19:07:56 -0400 Subject: [PATCH 3/5] terrafmt --- internal/service/ec2/ec2_host_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/service/ec2/ec2_host_test.go b/internal/service/ec2/ec2_host_test.go index 792cf1479710..cfcd629087a7 100644 --- a/internal/service/ec2/ec2_host_test.go +++ b/internal/service/ec2/ec2_host_test.go @@ -348,7 +348,7 @@ data "aws_outposts_outpost" "test" { } data "aws_outposts_assets" "test" { - arn = data.aws_outposts_outpost.test.arn + arn = data.aws_outposts_outpost.test.arn } resource "aws_ec2_host" "test" { From b269da928d2e5386d03f25a3c702f3afb9986c1c Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 19 Jul 2023 13:38:03 -0400 Subject: [PATCH 4/5] Tweak CHANGELOG entry. --- .changelog/32388.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.changelog/32388.txt b/.changelog/32388.txt index 0868df92dd2d..7fc9cd828692 100644 --- a/.changelog/32388.txt +++ b/.changelog/32388.txt @@ -1,3 +1,3 @@ ```release-note:enhancement -resource/ec2_host: Add `asset_id` argument +resource/aws_ec2_host: Add `asset_id` argument ``` \ No newline at end of file From ec434e5a2e2918c1e87272172d987e11dfabf5a1 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Wed, 19 Jul 2023 13:44:23 -0400 Subject: [PATCH 5/5] d/aws_ec2_host: Add 'asset_id' attribute. --- .changelog/32388.txt | 4 ++++ internal/service/ec2/ec2_host.go | 2 +- internal/service/ec2/ec2_host_data_source.go | 5 +++++ internal/service/ec2/ec2_host_data_source_test.go | 1 + website/docs/d/ec2_host.html.markdown | 1 + 5 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.changelog/32388.txt b/.changelog/32388.txt index 7fc9cd828692..c1fe5dfa38a8 100644 --- a/.changelog/32388.txt +++ b/.changelog/32388.txt @@ -1,3 +1,7 @@ ```release-note:enhancement resource/aws_ec2_host: Add `asset_id` argument +``` + +```release-note:enhancement +data-source/aws_ec2_host: Add `asset_id` attribute ``` \ No newline at end of file diff --git a/internal/service/ec2/ec2_host.go b/internal/service/ec2/ec2_host.go index 4b71dab74c44..60a5f37fd216 100644 --- a/internal/service/ec2/ec2_host.go +++ b/internal/service/ec2/ec2_host.go @@ -106,7 +106,7 @@ func resourceHostCreate(ctx context.Context, d *schema.ResourceData, meta interf } if v, ok := d.GetOk("asset_id"); ok { - input.AssetIds = []*string{aws.String(v.(string))} + input.AssetIds = aws.StringSlice([]string{v.(string)}) } if v, ok := d.GetOk("instance_family"); ok { diff --git a/internal/service/ec2/ec2_host_data_source.go b/internal/service/ec2/ec2_host_data_source.go index eb2fd8beedc1..68a0be7b1abd 100644 --- a/internal/service/ec2/ec2_host_data_source.go +++ b/internal/service/ec2/ec2_host_data_source.go @@ -33,6 +33,10 @@ func DataSourceHost() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "asset_id": { + Type: schema.TypeString, + Computed: true, + }, "auto_placement": { Type: schema.TypeString, Computed: true, @@ -118,6 +122,7 @@ func dataSourceHostRead(ctx context.Context, d *schema.ResourceData, meta interf Resource: fmt.Sprintf("dedicated-host/%s", d.Id()), }.String() d.Set("arn", arn) + d.Set("asset_id", host.AssetId) d.Set("auto_placement", host.AutoPlacement) d.Set("availability_zone", host.AvailabilityZone) d.Set("cores", host.HostProperties.Cores) diff --git a/internal/service/ec2/ec2_host_data_source_test.go b/internal/service/ec2/ec2_host_data_source_test.go index d7d29bc3aa8c..e1ba4f7b43a2 100644 --- a/internal/service/ec2/ec2_host_data_source_test.go +++ b/internal/service/ec2/ec2_host_data_source_test.go @@ -61,6 +61,7 @@ func TestAccEC2HostDataSource_filter(t *testing.T) { Config: testAccHostDataSourceConfig_filter(rName), Check: resource.ComposeTestCheckFunc( resource.TestCheckResourceAttrPair(dataSourceName, "arn", resourceName, "arn"), + resource.TestCheckResourceAttrPair(dataSourceName, "asset_id", resourceName, "asset_id"), resource.TestCheckResourceAttrPair(dataSourceName, "auto_placement", resourceName, "auto_placement"), resource.TestCheckResourceAttrPair(dataSourceName, "availability_zone", resourceName, "availability_zone"), resource.TestCheckResourceAttrSet(dataSourceName, "cores"), diff --git a/website/docs/d/ec2_host.html.markdown b/website/docs/d/ec2_host.html.markdown index c265fb237998..a7969315d5e8 100644 --- a/website/docs/d/ec2_host.html.markdown +++ b/website/docs/d/ec2_host.html.markdown @@ -57,6 +57,7 @@ This data source exports the following attributes in addition to the arguments a * `id` - ID of the Dedicated Host. * `arn` - ARN of the Dedicated Host. +* `asset_id` - The ID of the Outpost hardware asset on which the Dedicated Host is allocated. * `auto_placement` - Whether auto-placement is on or off. * `availability_zone` - Availability Zone of the Dedicated Host. * `cores` - Number of cores on the Dedicated Host.