diff --git a/.changelog/25464.txt b/.changelog/25464.txt new file mode 100644 index 00000000000..7f0a183a1a4 --- /dev/null +++ b/.changelog/25464.txt @@ -0,0 +1,7 @@ +```release-note:enhancement + resource/aws_ec2_host: Add `outpost_arn` argument + ``` + + ```release-note:enhancement + data-source/aws_ec2_host: Add `outpost_arn` attribute + ``` \ No newline at end of file diff --git a/internal/service/ec2/ec2_host.go b/internal/service/ec2/ec2_host.go index ff43b9b798b..6c44575b437 100644 --- a/internal/service/ec2/ec2_host.go +++ b/internal/service/ec2/ec2_host.go @@ -61,6 +61,11 @@ func ResourceHost() *schema.Resource { Optional: true, ExactlyOneOf: []string{"instance_family", "instance_type"}, }, + "outpost_arn": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "owner_id": { Type: schema.TypeString, Computed: true, @@ -91,6 +96,10 @@ func resourceHostCreate(d *schema.ResourceData, meta interface{}) error { input.InstanceType = aws.String(v.(string)) } + if v, ok := d.GetOk("outpost_arn"); ok { + input.OutpostArn = aws.String(v.(string)) + } + if len(tags) > 0 { input.TagSpecifications = tagSpecificationsFromKeyValueTags(tags, ec2.ResourceTypeDedicatedHost) } @@ -141,6 +150,7 @@ func resourceHostRead(d *schema.ResourceData, meta interface{}) error { d.Set("host_recovery", host.HostRecovery) d.Set("instance_family", host.HostProperties.InstanceFamily) d.Set("instance_type", host.HostProperties.InstanceType) + d.Set("outpost_arn", host.OutpostArn) d.Set("owner_id", host.OwnerId) tags := KeyValueTags(host.Tags).IgnoreAWS().IgnoreConfig(ignoreTagsConfig) diff --git a/internal/service/ec2/ec2_host_data_source.go b/internal/service/ec2/ec2_host_data_source.go index 73495a061c3..da5653c23a4 100644 --- a/internal/service/ec2/ec2_host_data_source.go +++ b/internal/service/ec2/ec2_host_data_source.go @@ -51,6 +51,10 @@ func DataSourceHost() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "outpost_arn": { + Type: schema.TypeString, + Computed: true, + }, "owner_id": { Type: schema.TypeString, Computed: true, @@ -95,6 +99,7 @@ func dataSourceHostRead(d *schema.ResourceData, meta interface{}) error { d.Set("host_recovery", host.HostRecovery) d.Set("instance_family", host.HostProperties.InstanceFamily) d.Set("instance_type", host.HostProperties.InstanceType) + d.Set("outpost_arn", host.OutpostArn) d.Set("owner_id", host.OwnerId) d.Set("sockets", host.HostProperties.Sockets) d.Set("total_vcpus", host.HostProperties.TotalVCpus) diff --git a/internal/service/ec2/ec2_host_data_source_test.go b/internal/service/ec2/ec2_host_data_source_test.go index 459dfd968b9..a231d7cce1d 100644 --- a/internal/service/ec2/ec2_host_data_source_test.go +++ b/internal/service/ec2/ec2_host_data_source_test.go @@ -31,6 +31,7 @@ func TestAccEC2HostDataSource_basic(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, "host_recovery", resourceName, "host_recovery"), resource.TestCheckResourceAttrPair(dataSourceName, "instance_family", resourceName, "instance_family"), resource.TestCheckResourceAttrPair(dataSourceName, "instance_type", resourceName, "instance_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "outpost_arn", resourceName, "outpost_arn"), resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), resource.TestCheckResourceAttrSet(dataSourceName, "sockets"), resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), @@ -62,6 +63,7 @@ func TestAccEC2HostDataSource_filter(t *testing.T) { resource.TestCheckResourceAttrPair(dataSourceName, "host_recovery", resourceName, "host_recovery"), resource.TestCheckResourceAttrPair(dataSourceName, "instance_family", resourceName, "instance_family"), resource.TestCheckResourceAttrPair(dataSourceName, "instance_type", resourceName, "instance_type"), + resource.TestCheckResourceAttrPair(dataSourceName, "outpost_arn", resourceName, "outpost_arn"), resource.TestCheckResourceAttrPair(dataSourceName, "owner_id", resourceName, "owner_id"), resource.TestCheckResourceAttrSet(dataSourceName, "sockets"), resource.TestCheckResourceAttrPair(dataSourceName, "tags.%", resourceName, "tags.%"), diff --git a/internal/service/ec2/ec2_host_test.go b/internal/service/ec2/ec2_host_test.go index d1af88d9598..b2e642f0328 100644 --- a/internal/service/ec2/ec2_host_test.go +++ b/internal/service/ec2/ec2_host_test.go @@ -34,6 +34,7 @@ func TestAccEC2Host_basic(t *testing.T) { resource.TestCheckResourceAttr(resourceName, "host_recovery", "off"), resource.TestCheckResourceAttr(resourceName, "instance_family", ""), resource.TestCheckResourceAttr(resourceName, "instance_type", "a1.large"), + resource.TestCheckResourceAttr(resourceName, "outpost_arn", ""), acctest.CheckResourceAttrAccountID(resourceName, "owner_id"), resource.TestCheckResourceAttr(resourceName, "tags.%", "0"), ), @@ -161,6 +162,34 @@ func TestAccEC2Host_tags(t *testing.T) { }) } +func TestAccEC2Host_outpost(t *testing.T) { + var host ec2.Host + resourceName := "aws_ec2_host.test" + outpostDataSourceName := "data.aws_outposts_outpost.test" + rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix) + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acctest.PreCheck(t); acctest.PreCheckOutpostsOutposts(t) }, + ErrorCheck: acctest.ErrorCheck(t, ec2.EndpointsID), + ProviderFactories: acctest.ProviderFactories, + CheckDestroy: testAccCheckHostDestroy, + Steps: []resource.TestStep{ + { + Config: testAccHostConfig_outpost(rName), + Check: resource.ComposeTestCheckFunc( + testAccCheckHostExists(resourceName, &host), + resource.TestCheckResourceAttrPair(resourceName, "outpost_arn", outpostDataSourceName, "arn"), + ), + }, + { + ResourceName: rName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + func testAccCheckHostExists(n string, v *ec2.Host) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] @@ -275,3 +304,23 @@ resource "aws_ec2_host" "test" { } `, tagKey1, tagValue1, tagKey2, tagValue2)) } + +func testAccHostConfig_outpost(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] +} + +resource "aws_ec2_host" "test" { + instance_family = "r5d" + availability_zone = data.aws_availability_zones.available.names[1] + outpost_arn = data.aws_outposts_outpost.test.arn + + tags = { + Name = %[1]q + } +} +`, rName)) +} diff --git a/website/docs/d/ec2_host.html.markdown b/website/docs/d/ec2_host.html.markdown index fcd06fe5dd4..80fade1142c 100644 --- a/website/docs/d/ec2_host.html.markdown +++ b/website/docs/d/ec2_host.html.markdown @@ -63,6 +63,7 @@ In addition to the attributes above, the following attributes are exported: * `host_recovery` - Indicates whether host recovery is enabled or disabled for the Dedicated Host. * `instance_family` - The instance family supported by the Dedicated Host. For example, "m5". * `instance_type` - The instance type supported by the Dedicated Host. For example, "m5.large". If the host supports multiple instance types, no instanceType is returned. +* `outpost_arn` - The Amazon Resource Name (ARN) of the AWS Outpost on which the Dedicated Host is allocated. * `owner_id` - The ID of the AWS account that owns the Dedicated Host. * `sockets` - The number of sockets on the Dedicated Host. * `total_vcpus` - The total number of vCPUs on the Dedicated Host. diff --git a/website/docs/r/ec2_host.html.markdown b/website/docs/r/ec2_host.html.markdown index 2dbf030dbae..2792902127c 100644 --- a/website/docs/r/ec2_host.html.markdown +++ b/website/docs/r/ec2_host.html.markdown @@ -31,7 +31,8 @@ The following arguments are supported: * `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`. * `instance_family` - (Optional) Specifies the instance family to be supported by the Dedicated Hosts. If you specify an instance family, the Dedicated Hosts support multiple instance types within that instance family. Exactly one of `instance_family` or `instance_type` must be specified. -* `instance_type` - (Optional) Specifies the instance type to be supported by the Dedicated Hosts. If you specify an instance type, the Dedicated Hosts support instances of the specified instance type only. Exactly one of `instance_family` or `instance_type` must be specified. +* `instance_type` - (Optional) Specifies the instance type to be supported by the Dedicated Hosts. If you specify an instance type, the Dedicated Hosts support instances of the specified instance type only. Exactly one of `instance_family` or `instance_type` must be specified. +* `outpost_arn` - (Optional) The Amazon Resource Name (ARN) of the AWS Outpost on which to allocate the Dedicated Host. * `tags` - (Optional) Map of tags to assign to this resource. If configured with a provider [`default_tags` configuration block](https://www.terraform.io/docs/providers/aws/index.html#default_tags-configuration-block) present, tags with matching keys will overwrite those defined at the provider-level. ## Attributes Reference