From 750a36c51ed284530bb27e3362157c007819a9b9 Mon Sep 17 00:00:00 2001 From: sneha somwanshi Date: Tue, 4 Nov 2014 16:38:30 +0530 Subject: [PATCH 1/2] AWS instance resource now supports tenancy --- builtin/providers/aws/resource_aws_instance.go | 8 ++++++++ builtin/providers/aws/resource_aws_instance_test.go | 1 + 2 files changed, 9 insertions(+) diff --git a/builtin/providers/aws/resource_aws_instance.go b/builtin/providers/aws/resource_aws_instance.go index c1f9261fb..cc7957769 100644 --- a/builtin/providers/aws/resource_aws_instance.go +++ b/builtin/providers/aws/resource_aws_instance.go @@ -124,6 +124,12 @@ func resourceAwsInstance() *schema.Resource { ForceNew: true, Optional: true, }, + "tenancy": &schema.Schema{ + Type: schema.TypeString, + Optional: true, + Computed: true, + ForceNew: true, + }, "tags": tagsSchema(), }, } @@ -156,6 +162,7 @@ func resourceAwsInstanceCreate(d *schema.ResourceData, meta interface{}) error { UserData: []byte(userData), EbsOptimized: d.Get("ebs_optimized").(bool), IamInstanceProfile: d.Get("iam_instance_profile").(string), + Tenancy: d.Get("tenancy").(string), } if v := d.Get("security_groups"); v != nil { @@ -330,6 +337,7 @@ func resourceAwsInstanceRead(d *schema.ResourceData, meta interface{}) error { d.Set("subnet_id", instance.SubnetId) d.Set("ebs_optimized", instance.EbsOptimized) d.Set("tags", tagsToMap(instance.Tags)) + d.Set("tenancy", instance.Tenancy) // Determine whether we're referring to security groups with // IDs or names. We use a heuristic to figure this out. By default, diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index ff7087732..1c91611dd 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -287,6 +287,7 @@ resource "aws_instance" "foo" { instance_type = "m1.small" subnet_id = "${aws_subnet.foo.id}" associate_public_ip_address = true + tenancy = "dedicated" } ` From 86aafdb839468541c1660322460f76a079297498 Mon Sep 17 00:00:00 2001 From: Sneha Somwanshi Date: Wed, 3 Dec 2014 15:58:51 +0530 Subject: [PATCH 2/2] test for tenancy schema --- .../aws/resource_aws_instance_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index a3c46c09a..4e07cbe0b 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -3,8 +3,10 @@ package aws import ( "fmt" "testing" + "reflect" "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/terraform" "github.com/mitchellh/goamz/ec2" ) @@ -247,6 +249,22 @@ func testAccCheckInstanceExists(n string, i *ec2.Instance) resource.TestCheckFun } } +func TestInstanceTenancySchema(t *testing.T) { + actualSchema := resourceAwsInstance().Schema["tenancy"] + 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) + } +} + const testAccInstanceConfig = ` resource "aws_security_group" "tf_test_foo" { name = "tf_test_foo"