From 95026b6266a60658d93490e4d62828c6a2ae2d1f Mon Sep 17 00:00:00 2001 From: Clint Shryock Date: Tue, 14 Apr 2015 11:23:26 -0500 Subject: [PATCH] provider/aws: Convert AWS VPC Peering to upstream --- .../resource_aws_vpc_peering_connection.go | 34 +++++++++---------- ...esource_aws_vpc_peering_connection_test.go | 9 ++--- 2 files changed, 22 insertions(+), 21 deletions(-) diff --git a/builtin/providers/aws/resource_aws_vpc_peering_connection.go b/builtin/providers/aws/resource_aws_vpc_peering_connection.go index 0f8c6185b..82fe55246 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection.go @@ -5,8 +5,8 @@ import ( "log" "time" - "github.com/hashicorp/aws-sdk-go/aws" - "github.com/hashicorp/aws-sdk-go/gen/ec2" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/schema" ) @@ -41,16 +41,16 @@ func resourceAwsVpcPeeringConnection() *schema.Resource { } func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + conn := meta.(*AWSClient).ec2SDKconn // Create the vpc peering connection - createOpts := &ec2.CreateVPCPeeringConnectionRequest{ + createOpts := &ec2.CreateVPCPeeringConnectionInput{ PeerOwnerID: aws.String(d.Get("peer_owner_id").(string)), PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)), VPCID: aws.String(d.Get("vpc_id").(string)), } log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts) - resp, err := ec2conn.CreateVPCPeeringConnection(createOpts) + resp, err := conn.CreateVPCPeeringConnection(createOpts) if err != nil { return fmt.Errorf("Error creating vpc peering connection: %s", err) } @@ -67,7 +67,7 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error stateConf := &resource.StateChangeConf{ Pending: []string{"pending"}, Target: "ready", - Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), + Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id()), Timeout: 1 * time.Minute, } if _, err := stateConf.WaitForState(); err != nil { @@ -80,8 +80,8 @@ func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error } func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn - pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() + conn := meta.(*AWSClient).ec2SDKconn + pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())() if err != nil { return err } @@ -95,15 +95,15 @@ func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error { d.Set("peer_owner_id", pc.AccepterVPCInfo.OwnerID) d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID) d.Set("vpc_id", pc.RequesterVPCInfo.VPCID) - d.Set("tags", tagsToMap(pc.Tags)) + d.Set("tags", tagsToMapSDK(pc.Tags)) return nil } func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + conn := meta.(*AWSClient).ec2SDKconn - if err := setTags(ec2conn, d); err != nil { + if err := setTagsSDK(conn, d); err != nil { return err } else { d.SetPartial("tags") @@ -113,10 +113,10 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error } func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error { - ec2conn := meta.(*AWSClient).ec2conn + conn := meta.(*AWSClient).ec2SDKconn - _, err := ec2conn.DeleteVPCPeeringConnection( - &ec2.DeleteVPCPeeringConnectionRequest{ + _, err := conn.DeleteVPCPeeringConnection( + &ec2.DeleteVPCPeeringConnectionInput{ VPCPeeringConnectionID: aws.String(d.Id()), }) return err @@ -127,8 +127,8 @@ func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { return func() (interface{}, string, error) { - resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsRequest{ - VPCPeeringConnectionIDs: []string{id}, + resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsInput{ + VPCPeeringConnectionIDs: []*string{aws.String(id)}, }) if err != nil { if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" { @@ -145,7 +145,7 @@ func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) r return nil, "", nil } - pc := &resp.VPCPeeringConnections[0] + pc := resp.VPCPeeringConnections[0] return pc, "ready", nil } 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 b3f30c3a1..146d92ca3 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -5,7 +5,8 @@ import ( "os" "testing" - "github.com/hashicorp/aws-sdk-go/gen/ec2" + "github.com/awslabs/aws-sdk-go/aws" + "github.com/awslabs/aws-sdk-go/service/ec2" "github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/terraform" ) @@ -34,7 +35,7 @@ func TestAccAWSVPCPeeringConnection_normal(t *testing.T) { } func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { - conn := testAccProvider.Meta().(*AWSClient).ec2conn + conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn for _, rs := range s.RootModule().Resources { if rs.Type != "aws_vpc_peering_connection" { @@ -42,8 +43,8 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { } describe, err := conn.DescribeVPCPeeringConnections( - &ec2.DescribeVPCPeeringConnectionsRequest{ - VPCPeeringConnectionIDs: []string{rs.Primary.ID}, + &ec2.DescribeVPCPeeringConnectionsInput{ + VPCPeeringConnectionIDs: []*string{aws.String(rs.Primary.ID)}, }) if err == nil {