Merge pull request #5959 from hashicorp/b-aws-vpc-peering-update

provider/aws: Fix issue re-creating deleted VPC peering connections
This commit is contained in:
Clint 2016-03-31 16:54:57 -05:00
commit f54b4afdc7
2 changed files with 56 additions and 4 deletions

View File

@ -104,10 +104,13 @@ func resourceAwsVPCPeeringRead(d *schema.ResourceData, meta interface{}) error {
// The failed status is a status that we can assume just means the // The failed status is a status that we can assume just means the
// connection is gone. Destruction isn't allowed, and it eventually // connection is gone. Destruction isn't allowed, and it eventually
// just "falls off" the console. See GH-2322 // just "falls off" the console. See GH-2322
if *pc.Status.Code == "failed" { if pc.Status != nil {
if *pc.Status.Code == "failed" || *pc.Status.Code == "deleted" {
log.Printf("[DEBUG] VPC Peering Connect (%s) in state (%s), removing", d.Id(), *pc.Status.Code)
d.SetId("") d.SetId("")
return nil return nil
} }
}
d.Set("accept_status", *pc.Status.Code) d.Set("accept_status", *pc.Status.Code)
d.Set("peer_owner_id", pc.AccepterVpcInfo.OwnerId) d.Set("peer_owner_id", pc.AccepterVpcInfo.OwnerId)

View File

@ -2,6 +2,7 @@ package aws
import ( import (
"fmt" "fmt"
"log"
"os" "os"
"testing" "testing"
@ -34,6 +35,45 @@ func TestAccAWSVPCPeeringConnection_basic(t *testing.T) {
}) })
} }
func TestAccAWSVPCPeeringConnection_plan(t *testing.T) {
var connection ec2.VpcPeeringConnection
// reach out and DELETE the VPC Peering connection outside of Terraform
testDestroy := func(*terraform.State) error {
conn := testAccProvider.Meta().(*AWSClient).ec2conn
log.Printf("[DEBUG] Test deleting VPC Peering connection")
_, err := conn.DeleteVpcPeeringConnection(
&ec2.DeleteVpcPeeringConnectionInput{
VpcPeeringConnectionId: connection.VpcPeeringConnectionId,
})
if err != nil {
return err
}
return nil
}
resource.Test(t, resource.TestCase{
PreCheck: func() {
testAccPreCheck(t)
if os.Getenv("AWS_ACCOUNT_ID") == "" {
t.Fatal("AWS_ACCOUNT_ID must be set")
}
},
Providers: testAccProviders,
CheckDestroy: testAccCheckAWSVpcPeeringConnectionDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccVpcPeeringConfig,
Check: resource.ComposeTestCheckFunc(
testAccCheckAWSVpcPeeringConnectionExists("aws_vpc_peering_connection.foo", &connection),
testDestroy,
),
ExpectNonEmptyPlan: true,
},
},
})
}
func TestAccAWSVPCPeeringConnection_tags(t *testing.T) { func TestAccAWSVPCPeeringConnection_tags(t *testing.T) {
var connection ec2.VpcPeeringConnection var connection ec2.VpcPeeringConnection
peerId := os.Getenv("TF_PEER_ID") peerId := os.Getenv("TF_PEER_ID")
@ -93,9 +133,12 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error {
return fmt.Errorf("Found vpc peering connection in unexpected state: %s", pc) return fmt.Errorf("Found vpc peering connection in unexpected state: %s", pc)
} }
// return error here; we've found the vpc_peering object we want, however
// it's not in an expected state
return fmt.Errorf("Fall through error for testAccCheckAWSVpcPeeringConnectionDestroy")
} }
return fmt.Errorf("Fall through error for testAccCheckAWSVpcPeeringConnectionDestroy") return nil
} }
func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc { func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc {
@ -130,6 +173,9 @@ func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeer
const testAccVpcPeeringConfig = ` const testAccVpcPeeringConfig = `
resource "aws_vpc" "foo" { resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"
tags {
Name = "TestAccAWSVPCPeeringConnection_basic"
}
} }
resource "aws_vpc" "bar" { resource "aws_vpc" "bar" {
@ -146,6 +192,9 @@ resource "aws_vpc_peering_connection" "foo" {
const testAccVpcPeeringConfigTags = ` const testAccVpcPeeringConfigTags = `
resource "aws_vpc" "foo" { resource "aws_vpc" "foo" {
cidr_block = "10.0.0.0/16" cidr_block = "10.0.0.0/16"
tags {
Name = "TestAccAWSVPCPeeringConnection_tags"
}
} }
resource "aws_vpc" "bar" { resource "aws_vpc" "bar" {