Skip to content

Commit

Permalink
Merge pull request #25464 from silvaalbert/ec2host-outpostarn
Browse files Browse the repository at this point in the history
Ec2host outpostarn
  • Loading branch information
ewbankkit committed Jun 18, 2022
2 parents 5259982 + f754d57 commit 171e75f
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 1 deletion.
7 changes: 7 additions & 0 deletions .changelog/25464.txt
Original file line number Diff line number Diff line change
@@ -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
```
10 changes: 10 additions & 0 deletions internal/service/ec2/ec2_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions internal/service/ec2/ec2_host_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/service/ec2/ec2_host_data_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.%"),
Expand Down Expand Up @@ -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.%"),
Expand Down
49 changes: 49 additions & 0 deletions internal/service/ec2/ec2_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
Expand Down Expand Up @@ -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]
Expand Down Expand Up @@ -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))
}
1 change: 1 addition & 0 deletions website/docs/d/ec2_host.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
3 changes: 2 additions & 1 deletion website/docs/r/ec2_host.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 171e75f

Please sign in to comment.