Merge pull request #1522 from hashicorp/f-aws-upstream-vpc-peering

provider/aws: Convert AWS VPC Peering to upstream
This commit is contained in:
Clint 2015-04-15 14:14:02 -05:00
commit f948b6205a
2 changed files with 22 additions and 21 deletions

View File

@ -5,8 +5,8 @@ import (
"log" "log"
"time" "time"
"github.com/hashicorp/aws-sdk-go/aws" "github.com/awslabs/aws-sdk-go/aws"
"github.com/hashicorp/aws-sdk-go/gen/ec2" "github.com/awslabs/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
) )
@ -41,16 +41,16 @@ func resourceAwsVpcPeeringConnection() *schema.Resource {
} }
func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error { func resourceAwsVpcPeeringCreate(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
// Create the vpc peering connection // Create the vpc peering connection
createOpts := &ec2.CreateVPCPeeringConnectionRequest{ createOpts := &ec2.CreateVPCPeeringConnectionInput{
PeerOwnerID: aws.String(d.Get("peer_owner_id").(string)), PeerOwnerID: aws.String(d.Get("peer_owner_id").(string)),
PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)), PeerVPCID: aws.String(d.Get("peer_vpc_id").(string)),
VPCID: aws.String(d.Get("vpc_id").(string)), VPCID: aws.String(d.Get("vpc_id").(string)),
} }
log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts) log.Printf("[DEBUG] VpcPeeringCreate create config: %#v", createOpts)
resp, err := ec2conn.CreateVPCPeeringConnection(createOpts) resp, err := conn.CreateVPCPeeringConnection(createOpts)
if err != nil { if err != nil {
return fmt.Errorf("Error creating vpc peering connection: %s", err) 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{ stateConf := &resource.StateChangeConf{
Pending: []string{"pending"}, Pending: []string{"pending"},
Target: "ready", Target: "ready",
Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id()), Refresh: resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id()),
Timeout: 1 * time.Minute, Timeout: 1 * time.Minute,
} }
if _, err := stateConf.WaitForState(); err != nil { 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 { func resourceAwsVpcPeeringRead(d *schema.ResourceData, meta interface{}) error {
ec2conn := meta.(*AWSClient).ec2conn conn := meta.(*AWSClient).ec2SDKconn
pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(ec2conn, d.Id())() pcRaw, _, err := resourceAwsVpcPeeringConnectionStateRefreshFunc(conn, d.Id())()
if err != nil { if err != nil {
return err 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_owner_id", pc.AccepterVPCInfo.OwnerID)
d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID) d.Set("peer_vpc_id", pc.AccepterVPCInfo.VPCID)
d.Set("vpc_id", pc.RequesterVPCInfo.VPCID) d.Set("vpc_id", pc.RequesterVPCInfo.VPCID)
d.Set("tags", tagsToMap(pc.Tags)) d.Set("tags", tagsToMapSDK(pc.Tags))
return nil return nil
} }
func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error { 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 return err
} else { } else {
d.SetPartial("tags") d.SetPartial("tags")
@ -113,10 +113,10 @@ func resourceAwsVpcPeeringUpdate(d *schema.ResourceData, meta interface{}) error
} }
func resourceAwsVpcPeeringDelete(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( _, err := conn.DeleteVPCPeeringConnection(
&ec2.DeleteVPCPeeringConnectionRequest{ &ec2.DeleteVPCPeeringConnectionInput{
VPCPeeringConnectionID: aws.String(d.Id()), VPCPeeringConnectionID: aws.String(d.Id()),
}) })
return err return err
@ -127,8 +127,8 @@ func resourceAwsVpcPeeringDelete(d *schema.ResourceData, meta interface{}) error
func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc { func resourceAwsVpcPeeringConnectionStateRefreshFunc(conn *ec2.EC2, id string) resource.StateRefreshFunc {
return func() (interface{}, string, error) { return func() (interface{}, string, error) {
resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsRequest{ resp, err := conn.DescribeVPCPeeringConnections(&ec2.DescribeVPCPeeringConnectionsInput{
VPCPeeringConnectionIDs: []string{id}, VPCPeeringConnectionIDs: []*string{aws.String(id)},
}) })
if err != nil { if err != nil {
if ec2err, ok := err.(aws.APIError); ok && ec2err.Code == "InvalidVpcPeeringConnectionID.NotFound" { 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 return nil, "", nil
} }
pc := &resp.VPCPeeringConnections[0] pc := resp.VPCPeeringConnections[0]
return pc, "ready", nil return pc, "ready", nil
} }

View File

@ -5,7 +5,8 @@ import (
"os" "os"
"testing" "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/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
) )
@ -34,7 +35,7 @@ func TestAccAWSVPCPeeringConnection_normal(t *testing.T) {
} }
func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn conn := testAccProvider.Meta().(*AWSClient).ec2SDKconn
for _, rs := range s.RootModule().Resources { for _, rs := range s.RootModule().Resources {
if rs.Type != "aws_vpc_peering_connection" { if rs.Type != "aws_vpc_peering_connection" {
@ -42,8 +43,8 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
} }
describe, err := conn.DescribeVPCPeeringConnections( describe, err := conn.DescribeVPCPeeringConnections(
&ec2.DescribeVPCPeeringConnectionsRequest{ &ec2.DescribeVPCPeeringConnectionsInput{
VPCPeeringConnectionIDs: []string{rs.Primary.ID}, VPCPeeringConnectionIDs: []*string{aws.String(rs.Primary.ID)},
}) })
if err == nil { if err == nil {