provider/aws: Update testAccAwsVpnConnectionRouteDestroy method

This commit is contained in:
clint shryock 2016-01-06 10:22:54 -06:00
parent 055482a9f5
commit 2be03ddf06
1 changed files with 51 additions and 4 deletions

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/ec2" "github.com/aws/aws-sdk-go/service/ec2"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
@ -44,11 +45,57 @@ func TestAccAWSVpnConnectionRoute_basic(t *testing.T) {
} }
func testAccAwsVpnConnectionRouteDestroy(s *terraform.State) error { func testAccAwsVpnConnectionRouteDestroy(s *terraform.State) error {
if len(s.RootModule().Resources) > 0 { conn := testAccProvider.Meta().(*AWSClient).ec2conn
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources) for _, rs := range s.RootModule().Resources {
} if rs.Type != "aws_vpn_connection_route" {
continue
}
return nil cidrBlock, vpnConnectionId := resourceAwsVpnConnectionRouteParseId(rs.Primary.ID)
routeFilters := []*ec2.Filter{
&ec2.Filter{
Name: aws.String("route.destination-cidr-block"),
Values: []*string{aws.String(cidrBlock)},
},
&ec2.Filter{
Name: aws.String("vpn-connection-id"),
Values: []*string{aws.String(vpnConnectionId)},
},
}
resp, err := conn.DescribeVpnConnections(&ec2.DescribeVpnConnectionsInput{
Filters: routeFilters,
})
if err != nil {
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
// not found, all good
return nil
}
return err
}
var vpnc *ec2.VpnConnection
if resp != nil {
// range over the connections and isolate the one we created
for _, v := range resp.VpnConnections {
if *v.VpnConnectionId == vpnConnectionId {
vpnc = v
}
}
if vpnc == nil {
// vpn connection not found, so that's good...
return nil
}
if vpnc.State != nil && *vpnc.State == "deleted" {
return nil
}
}
}
return fmt.Errorf("Fall through error, Check Destroy criteria not met")
} }
func testAccAwsVpnConnectionRoute( func testAccAwsVpnConnectionRoute(