From dd807c79ff832105d4385506045529e448f0172e Mon Sep 17 00:00:00 2001 From: myoung34 Date: Wed, 28 Dec 2016 16:48:24 -0600 Subject: [PATCH] Add support for instance tenancy in `aws_opsworks_instance` (#10885) --- .../aws/resource_aws_opsworks_instance.go | 25 +++++++++++++++++++ .../resource_aws_opsworks_instance_test.go | 9 +++++++ .../aws/aws-sdk-go/service/opsworks/api.go | 3 +++ .../aws/r/opsworks_instance.html.markdown | 2 ++ 4 files changed, 39 insertions(+) diff --git a/builtin/providers/aws/resource_aws_opsworks_instance.go b/builtin/providers/aws/resource_aws_opsworks_instance.go index bf1dbfdf30..d6dbf912a6 100644 --- a/builtin/providers/aws/resource_aws_opsworks_instance.go +++ b/builtin/providers/aws/resource_aws_opsworks_instance.go @@ -276,6 +276,13 @@ func resourceAwsOpsworksInstance() *schema.Resource { ForceNew: true, }, + "tenancy": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ValidateFunc: validateTenancy, + }, + "virtualization_type": &schema.Schema{ Type: schema.TypeString, Optional: true, @@ -429,6 +436,15 @@ func validateArchitecture(v interface{}, k string) (ws []string, errors []error) return } +func validateTenancy(v interface{}, k string) (ws []string, errors []error) { + value := v.(string) + if value != "dedicated" && value != "default" && value != "host" { + errors = append(errors, fmt.Errorf( + "%q must be one of \"dedicated\", \"default\" or \"host\"", k)) + } + return +} + func validateAutoScalingType(v interface{}, k string) (ws []string, errors []error) { value := v.(string) if value != "load" && value != "timer" { @@ -561,6 +577,7 @@ func resourceAwsOpsworksInstanceRead(d *schema.ResourceData, meta interface{}) e d.Set("stack_id", instance.StackId) d.Set("status", instance.Status) d.Set("subnet_id", instance.SubnetId) + d.Set("tenancy", instance.Tenancy) d.Set("virtualization_type", instance.VirtualizationType) // Read BlockDeviceMapping @@ -646,6 +663,10 @@ func resourceAwsOpsworksInstanceCreate(d *schema.ResourceData, meta interface{}) req.SubnetId = aws.String(v.(string)) } + if v, ok := d.GetOk("tenancy"); ok { + req.Tenancy = aws.String(v.(string)) + } + if v, ok := d.GetOk("virtualization_type"); ok { req.VirtualizationType = aws.String(v.(string)) } @@ -800,6 +821,10 @@ func resourceAwsOpsworksInstanceUpdate(d *schema.ResourceData, meta interface{}) req.SshKeyName = aws.String(v.(string)) } + if v, ok := d.GetOk("tenancy"); ok { + req.Tenancy = aws.String(v.(string)) + } + log.Printf("[DEBUG] Updating OpsWorks instance: %s", d.Id()) _, err = client.UpdateInstance(req) diff --git a/builtin/providers/aws/resource_aws_opsworks_instance_test.go b/builtin/providers/aws/resource_aws_opsworks_instance_test.go index e79f8bb45d..7b68cd1796 100644 --- a/builtin/providers/aws/resource_aws_opsworks_instance_test.go +++ b/builtin/providers/aws/resource_aws_opsworks_instance_test.go @@ -44,6 +44,9 @@ func TestAccAWSOpsworksInstance(t *testing.T) { resource.TestCheckResourceAttr( "aws_opsworks_instance.tf-acc", "architecture", "x86_64", ), + resource.TestCheckResourceAttr( + "aws_opsworks_instance.tf-acc", "tenancy", "default", + ), resource.TestCheckResourceAttr( "aws_opsworks_instance.tf-acc", "os", "Amazon Linux 2014.09", // inherited from opsworks_stack_test ), @@ -73,6 +76,9 @@ func TestAccAWSOpsworksInstance(t *testing.T) { resource.TestCheckResourceAttr( "aws_opsworks_instance.tf-acc", "os", "Amazon Linux 2015.09", ), + resource.TestCheckResourceAttr( + "aws_opsworks_instance.tf-acc", "tenancy", "default", + ), ), }, }, @@ -125,6 +131,9 @@ func testAccCheckAWSOpsworksInstanceAttributes( if *opsinst.Architecture != "x86_64" { return fmt.Errorf("Unexpected architecture: %s", *opsinst.Architecture) } + if *opsinst.Tenancy != "default" { + return fmt.Errorf("Unexpected tenancy: %s", *opsinst.Tenancy) + } if *opsinst.InfrastructureClass != "ec2" { return fmt.Errorf("Unexpected infrastructure class: %s", *opsinst.InfrastructureClass) } diff --git a/vendor/github.com/aws/aws-sdk-go/service/opsworks/api.go b/vendor/github.com/aws/aws-sdk-go/service/opsworks/api.go index d78b27a5fa..f5f84ad204 100644 --- a/vendor/github.com/aws/aws-sdk-go/service/opsworks/api.go +++ b/vendor/github.com/aws/aws-sdk-go/service/opsworks/api.go @@ -14069,6 +14069,9 @@ type UpdateInstanceInput struct { // The instance's Amazon EC2 key name. SshKeyName *string `type:"string"` + + // The instance's placement tenancy. + Tenancy *string `type:"string"` } // String returns the string representation diff --git a/website/source/docs/providers/aws/r/opsworks_instance.html.markdown b/website/source/docs/providers/aws/r/opsworks_instance.html.markdown index 8201b2e4f7..e1256c12e1 100644 --- a/website/source/docs/providers/aws/r/opsworks_instance.html.markdown +++ b/website/source/docs/providers/aws/r/opsworks_instance.html.markdown @@ -47,6 +47,7 @@ The following arguments are supported: * `ssh_key_name` - (Optional) Name of the SSH keypair that instances will have by default. * `agent_version` - (Optional) The AWS OpsWorks agent to install. Defaults to `"INHERIT"`. * `subnet_id` - (Optional) Subnet ID to attach to +* `tenancy` - (Optional) Instance tenancy to use. Can be one of `"default"`, `"dedicated"` or `"host"` * `virtualization_type` - (Optional) Keyword to choose what virtualization mode created instances will use. Can be either `"paravirtual"` or `"hvm"`. * `root_block_device` - (Optional) Customize details about the root block @@ -128,5 +129,6 @@ The following attributes are exported: for your VPC * `private_ip` - The private IP address assigned to the instance * `subnet_id` - The VPC subnet ID. +* `tenancy` - The Instance tenancy * `security_group_ids` - The associated security groups.