provider/aws: Fix issue re-creating deleted VPC peering connections
This commit is contained in:
parent
71995eaea1
commit
2575b9f5d4
|
@ -104,9 +104,12 @@ func resourceAwsVPCPeeringRead(d *schema.ResourceData, meta interface{}) error {
|
|||
// The failed status is a status that we can assume just means the
|
||||
// connection is gone. Destruction isn't allowed, and it eventually
|
||||
// just "falls off" the console. See GH-2322
|
||||
if *pc.Status.Code == "failed" {
|
||||
d.SetId("")
|
||||
return nil
|
||||
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("")
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
d.Set("accept_status", *pc.Status.Code)
|
||||
|
|
|
@ -2,6 +2,7 @@ package aws
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"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) {
|
||||
var connection ec2.VpcPeeringConnection
|
||||
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 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 {
|
||||
|
@ -130,6 +173,9 @@ func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeer
|
|||
const testAccVpcPeeringConfig = `
|
||||
resource "aws_vpc" "foo" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
tags {
|
||||
Name = "TestAccAWSVPCPeeringConnection_basic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_vpc" "bar" {
|
||||
|
@ -146,6 +192,9 @@ resource "aws_vpc_peering_connection" "foo" {
|
|||
const testAccVpcPeeringConfigTags = `
|
||||
resource "aws_vpc" "foo" {
|
||||
cidr_block = "10.0.0.0/16"
|
||||
tags {
|
||||
Name = "TestAccAWSVPCPeeringConnection_tags"
|
||||
}
|
||||
}
|
||||
|
||||
resource "aws_vpc" "bar" {
|
||||
|
|
Loading…
Reference in New Issue