From 840e6f4826afd12e0fa7ad41ee6c9cedd1f0726f Mon Sep 17 00:00:00 2001 From: Rahul Menon Date: Wed, 4 Mar 2015 18:37:30 +0530 Subject: [PATCH] Added Tagging --- builtin/providers/aws/resource_aws_vpc.go | 26 ++++---- .../providers/aws/resource_aws_vpc_test.go | 64 +++++++++---------- 2 files changed, 45 insertions(+), 45 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc.go b/builtin/providers/aws/resource_aws_vpc.go index 4d1d871ba..d1234e637 100644 --- a/builtin/providers/aws/resource_aws_vpc.go +++ b/builtin/providers/aws/resource_aws_vpc.go @@ -58,13 +58,13 @@ func resourceAwsVpc() *schema.Resource { Computed: true, }, - // "tags": tagsSchema(), + "tags": tagsSchema(), }, } } func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEc2conn + ec2conn := meta.(*AWSClient).awsEC2conn instance_tenancy := "default" if v, ok := d.GetOk("instance_tenancy"); ok { instance_tenancy = v.(string) @@ -110,7 +110,7 @@ func resourceAwsVpcCreate(d *schema.ResourceData, meta interface{}) error { } func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEc2conn + ec2conn := meta.(*AWSClient).awsEC2conn // Refresh the VPC state vpcRaw, _, err := VPCStateRefreshFunc(ec2conn, d.Id())() @@ -127,8 +127,8 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { vpcid := d.Id() d.Set("cidr_block", vpc.CIDRBlock) - // Tags - TBD rmenn - //d.Set("tags", tagsToMap(vpc.Tags)) + // Tags + d.Set("tags", tagsToMapSDK(vpc.Tags)) // Attributes attribute := "enableDnsSupport" @@ -180,7 +180,7 @@ func resourceAwsVpcRead(d *schema.ResourceData, meta interface{}) error { } func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEc2conn + ec2conn := meta.(*AWSClient).awsEC2conn // Turn on partial mode d.Partial(true) @@ -219,19 +219,19 @@ func resourceAwsVpcUpdate(d *schema.ResourceData, meta interface{}) error { d.SetPartial("enable_dns_support") } - //Tagging Support need to be worked on - rmenn - // if err := setTags(ec2conn, d); err != nil { - // return err - // } else { - // d.SetPartial("tags") - // } + + if err := setTagsSDK(ec2conn, d); err != nil { + return err + } else { + d.SetPartial("tags") + } d.Partial(false) return resourceAwsVpcRead(d, meta) } func resourceAwsVpcDelete(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).awsEc2conn + ec2conn := meta.(*AWSClient).awsEC2conn vpcID := d.Id() DeleteVpcOpts := &ec2.DeleteVPCRequest{ VPCID: &vpcID, diff --git a/builtin/providers/aws/resource_aws_vpc_test.go b/builtin/providers/aws/resource_aws_vpc_test.go index 7570a1873..7e324a5d9 100644 --- a/builtin/providers/aws/resource_aws_vpc_test.go +++ b/builtin/providers/aws/resource_aws_vpc_test.go @@ -50,36 +50,36 @@ func TestAccVpc_dedicatedTenancy(t *testing.T) { }) } -//func TestAccVpc_tags(t *testing.T) { -// var vpc ec2.VPC -// -// resource.Test(t, resource.TestCase{ -// PreCheck: func() { testAccPreCheck(t) }, -// Providers: testAccProviders, -// CheckDestroy: testAccCheckVpcDestroy, -// Steps: []resource.TestStep{ -// resource.TestStep{ -// Config: testAccVpcConfigTags, -// Check: resource.ComposeTestCheckFunc( -// testAccCheckVpcExists("aws_vpc.foo", &vpc), -// testAccCheckVpcCidr(&vpc, "10.1.0.0/16"), -// resource.TestCheckResourceAttr( -// "aws_vpc.foo", "cidr_block", "10.1.0.0/16"), -// testAccCheckTags(&vpc.Tags, "foo", "bar"), -// ), -// }, -// -// resource.TestStep{ -// Config: testAccVpcConfigTagsUpdate, -// Check: resource.ComposeTestCheckFunc( -// testAccCheckVpcExists("aws_vpc.foo", &vpc), -// testAccCheckTags(&vpc.Tags, "foo", ""), -// testAccCheckTags(&vpc.Tags, "bar", "baz"), -// ), -// }, -// }, -// }) -//} +func TestAccVpc_tags(t *testing.T) { + var vpc ec2.VPC + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccVpcConfigTags, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcExists("aws_vpc.foo", &vpc), + testAccCheckVpcCidr(&vpc, "10.1.0.0/16"), + resource.TestCheckResourceAttr( + "aws_vpc.foo", "cidr_block", "10.1.0.0/16"), + testAccCheckTagsSDK(&vpc.Tags, "foo", "bar"), + ), + }, + + resource.TestStep{ + Config: testAccVpcConfigTagsUpdate, + Check: resource.ComposeTestCheckFunc( + testAccCheckVpcExists("aws_vpc.foo", &vpc), + testAccCheckTagsSDK(&vpc.Tags, "foo", ""), + testAccCheckTagsSDK(&vpc.Tags, "bar", "baz"), + ), + }, + }, + }) +} func TestAccVpcUpdate(t *testing.T) { var vpc ec2.VPC @@ -111,7 +111,7 @@ func TestAccVpcUpdate(t *testing.T) { } func testAccCheckVpcDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).awsEc2conn + conn := testAccProvider.Meta().(*AWSClient).awsEC2conn for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc" { @@ -166,7 +166,7 @@ func testAccCheckVpcExists(n string, vpc *ec2.VPC) resource.TestCheckFunc { return fmt.Errorf("No VPC ID is set") } - conn := testAccProvider.Meta().(*AWSClient).awsEc2conn + conn := testAccProvider.Meta().(*AWSClient).awsEC2conn DescribeVpcOpts := &ec2.DescribeVPCsRequest{ VPCIDs: []string{rs.Primary.ID}, }