diff --git a/aws/data_source_aws_instance.go b/aws/data_source_aws_instance.go index 0c49381cb5f..080211b9835 100644 --- a/aws/data_source_aws_instance.go +++ b/aws/data_source_aws_instance.go @@ -51,6 +51,10 @@ func dataSourceAwsInstance() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "host_id": { + Type: schema.TypeString, + Computed: true, + }, "key_name": { Type: schema.TypeString, Computed: true, @@ -349,6 +353,9 @@ func instanceDescriptionAttributes(d *schema.ResourceData, instance *ec2.Instanc if instance.Placement.Tenancy != nil { d.Set("tenancy", instance.Placement.Tenancy) } + if instance.Placement.HostId != nil { + d.Set("host_id", instance.Placement.HostId) + } d.Set("ami", instance.ImageId) d.Set("instance_type", instance.InstanceType) d.Set("key_name", instance.KeyName) diff --git a/aws/resource_aws_instance.go b/aws/resource_aws_instance.go index e8e44f4d646..1076494d30d 100644 --- a/aws/resource_aws_instance.go +++ b/aws/resource_aws_instance.go @@ -287,7 +287,12 @@ func resourceAwsInstance() *schema.Resource { Computed: true, ForceNew: true, }, - + "host_id": { + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, "cpu_core_count": { Type: schema.TypeInt, Optional: true, @@ -708,6 +713,9 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error { if instance.Placement.Tenancy != nil { d.Set("tenancy", instance.Placement.Tenancy) } + if instance.Placement.HostId != nil { + d.Set("host_id", instance.Placement.HostId) + } if instance.CpuOptions != nil { d.Set("cpu_core_count", instance.CpuOptions.CoreCount) @@ -1821,6 +1829,9 @@ func buildAwsInstanceOpts( if v := d.Get("tenancy").(string); v != "" { opts.Placement.Tenancy = aws.String(v) } + if v := d.Get("host_id").(string); v != "" { + opts.Placement.HostId = aws.String(v) + } if v := d.Get("cpu_core_count").(int); v > 0 { tc := d.Get("cpu_threads_per_core").(int) diff --git a/aws/resource_aws_instance_test.go b/aws/resource_aws_instance_test.go index e081db5f581..f6fad820400 100644 --- a/aws/resource_aws_instance_test.go +++ b/aws/resource_aws_instance_test.go @@ -2091,6 +2091,22 @@ func TestInstanceTenancySchema(t *testing.T) { } } +func TestInstanceHostIDSchema(t *testing.T) { + actualSchema := resourceAwsInstance().Schema["host_id"] + expectedSchema := &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + } + if !reflect.DeepEqual(actualSchema, expectedSchema) { + t.Fatalf( + "Got:\n\n%#v\n\nExpected:\n\n%#v\n", + actualSchema, + expectedSchema) + } +} + func TestInstanceCpuCoreCountSchema(t *testing.T) { actualSchema := resourceAwsInstance().Schema["cpu_core_count"] expectedSchema := &schema.Schema{ diff --git a/website/docs/d/instance.html.markdown b/website/docs/d/instance.html.markdown index 84b3726874e..f462d6f92a8 100644 --- a/website/docs/d/instance.html.markdown +++ b/website/docs/d/instance.html.markdown @@ -102,6 +102,7 @@ interpolation. * `user_data` - The User Data supplied to the Instance. * `tags` - A mapping of tags assigned to the Instance. * `tenancy` - The tenancy of the instance: `dedicated`, `default`, `host`. +* `host_id` - The Id of the dedicated host the instance will be assigned to. * `vpc_security_group_ids` - The associated security groups in a non-default VPC. * `credit_specification` - The credit specification of the Instance. diff --git a/website/docs/r/instance.html.markdown b/website/docs/r/instance.html.markdown index 38f0f6b770a..179a9892bee 100644 --- a/website/docs/r/instance.html.markdown +++ b/website/docs/r/instance.html.markdown @@ -54,6 +54,7 @@ The following arguments are supported: * `availability_zone` - (Optional) The AZ to start the instance in. * `placement_group` - (Optional) The Placement Group to start the instance in. * `tenancy` - (Optional) The tenancy of the instance (if the instance is running in a VPC). An instance with a tenancy of dedicated runs on single-tenant hardware. The host tenancy is not supported for the import-instance command. +* `host_id` - (optional) The Id of a dedicated host that the instance will be assigned to. Use when an instance is to be launched on a specific dedicated host. * `cpu_core_count` - (Optional) Sets the number of CPU cores for an instance. This option is only supported on creation of instance type that support CPU Options [CPU Cores and Threads Per CPU Core Per Instance Type](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/instance-optimize-cpu.html#cpu-options-supported-instances-values) - specifying this option for unsupported instance types will return an error from the EC2 API.