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 7e85659f2e..6393d4564c 100644 --- a/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go +++ b/builtin/providers/aws/resource_aws_vpc_peering_connection_test.go @@ -70,14 +70,32 @@ func testAccCheckAWSVpcPeeringConnectionDestroy(s *terraform.State) error { VpcPeeringConnectionIds: []*string{aws.String(rs.Primary.ID)}, }) - if err == nil { - if len(describe.VpcPeeringConnections) != 0 { - return fmt.Errorf("vpc peering connection still exists") + if err != nil { + return err + } + + var pc *ec2.VpcPeeringConnection + for _, c := range describe.VpcPeeringConnections { + if rs.Primary.ID == *c.VpcPeeringConnectionId { + pc = c } } + + if pc == nil { + // not found + return nil + } + + if pc.Status != nil { + if *pc.Status.Code == "deleted" { + return nil + } + return fmt.Errorf("Found vpc peering connection in unexpected state: %s", pc) + } + } - return nil + return fmt.Errorf("Fall through error for testAccCheckAWSVpcPeeringConnectionDestroy") } func testAccCheckAWSVpcPeeringConnectionExists(n string, connection *ec2.VpcPeeringConnection) resource.TestCheckFunc {