From c2fa397ec8835ecfb664b641320d470826393b38 Mon Sep 17 00:00:00 2001 From: John Engelman Date: Fri, 24 Apr 2015 16:12:20 -0500 Subject: [PATCH] Fix for #1664. Apply AWS VPC Peering Conn. tags on create. --- .../resource_aws_vpc_peering_connection.go | 3 +- ...esource_aws_vpc_peering_connection_test.go | 65 +++++++++++++++++-- 2 files changed, 60 insertions(+), 8 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index 17c9baf6a..5a3d8bda1 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -76,7 +76,8 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error d.Id(), err) } - return nil + // Update our attributes and return + return resourceAwsVpcPeeringUpdate(d, meta) } func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go index 2a604c7bc..30823b35f 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -12,7 +12,7 @@ import ( ) func TestAccAWSVPCPeeringConnection_normal(t *testing.T) { - var conf ec2.Address + var connection ec2.VPCPeeringConnection resource.Test(t, resource.TestCase{ PreCheck: func() { @@ -27,7 +27,26 @@ func TestAccAWSVPCPeeringConnection_normal(t *testing.T) { resource.TestStep{ Config: testAccVpcPeeringConfig, Check: resource.ComposeTestCheckFunc( - testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &conf), + testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &connection), + ), + }, + }, + }) +} + +func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { + var connection ec2.VPCPeeringConnection + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckVpcDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccVpcPeeringConfigTags, + Check: resource.ComposeTestCheckFunc( + testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &connection), + testAccCheckTagsSDK(&connection.Tags, "foo", "bar"), ), }, }, @@ -57,7 +76,7 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { return nil } -func testAccCheckAWSVpcPeeringConnectionExists(n string, res *ec2.Address) resource.TestCheckFunc { +func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VPCPeeringConnection) resource.TestCheckFunc { return func(s *terraform.State) error { rs, ok := s.RootModule().Resources[n] if !ok { @@ -68,21 +87,53 @@ func testAccCheckAWSVpcPeeringConnectionExists(n string, res *ec2.Address) resou return fmt.Errorf("No vpc peering connection id is set") } + conn := testAccProvider.Meta().(*AWSClient).ec2conn + resp, err := conn.DescribeVPCPeeringConnections( + &ec2.DescribeVPCPeeringConnectionsInput{ + VPCPeeringConnectionIDs: []*string{aws.String(rs.Primary.ID)}, + }) + if err != nil { + return err + } + if len(resp.VPCPeeringConnections) == 0 { + return fmt.Errorf("VPC peering connection not found") + } + + *connection = *resp.VPCPeeringConnections[0] + return nil } } const testAccVpcPeeringConfig = ` resource "aws_vpc" "foo" { - cidr_block = "10.0.0.0/16" + cidr_block = "10.0.0.0/16" } resource "aws_vpc" "bar" { - cidr_block = "10.1.0.0/16" + cidr_block = "10.1.0.0/16" } resource "aws_vpc_peering_connection" "foo" { - vpc_id = "${aws_vpc.foo.id}" - peer_vpc_id = "${aws_vpc.bar.id}" + vpc_id = "${aws_vpc.foo.id}" + peer_vpc_id = "${aws_vpc.bar.id}" +} +` + +const testAccVpcPeeringConfigTags = ` +resource "aws_vpc" "foo" { + cidr_block = "10.0.0.0/16" +} + +resource "aws_vpc" "bar" { + cidr_block = "10.1.0.0/16" +} + +resource "aws_vpc_peering_connection" "foo" { + vpc_id = "${aws_vpc.foo.id}" + peer_vpc_id = "${aws_vpc.bar.id}" + tags { + foo = "bar" + } } `