Skip to content

Commit

Permalink
Merge pull request #6767 from cfullerton/master
Browse files Browse the repository at this point in the history
Added Dedicated Host ID field to aws_instance resource
  • Loading branch information
bflad authored Dec 13, 2018
2 parents 4206995 + 89cc0d6 commit a558529
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 1 deletion.
7 changes: 7 additions & 0 deletions aws/data_source_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 12 additions & 1 deletion aws/resource_aws_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
16 changes: 16 additions & 0 deletions aws/resource_aws_instance_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions website/docs/d/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
1 change: 1 addition & 0 deletions website/docs/r/instance.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit a558529

Please sign in to comment.