provider/aws: fix CheckDestroy for aws_eip tests

This commit is contained in:
Paul Hinze 2015-12-22 07:34:06 -06:00
parent 51732ac9eb
commit 10cc513ae0
1 changed files with 29 additions and 17 deletions

View File

@ -86,26 +86,38 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error {
continue continue
} }
req := &ec2.DescribeAddressesInput{ if strings.Contains(rs.Primary.ID, "eipalloc") {
PublicIps: []*string{aws.String(rs.Primary.ID)}, req := &ec2.DescribeAddressesInput{
} AllocationIds: []*string{aws.String(rs.Primary.ID)},
describe, err := conn.DescribeAddresses(req) }
describe, err := conn.DescribeAddresses(req)
if err == nil { if err != nil {
if len(describe.Addresses) != 0 && // Verify the error is what we want
*describe.Addresses[0].PublicIp == rs.Primary.ID { if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" {
return fmt.Errorf("EIP still exists") continue
}
return err
} }
}
// Verify the error if len(describe.Addresses) > 0 {
providerErr, ok := err.(awserr.Error) return fmt.Errorf("still exists")
if !ok { }
return err } else {
} req := &ec2.DescribeAddressesInput{
PublicIps: []*string{aws.String(rs.Primary.ID)},
}
describe, err := conn.DescribeAddresses(req)
if err != nil {
// Verify the error is what we want
if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidAllocationID.NotFound" {
continue
}
return err
}
if providerErr.Code() != "InvalidAllocationID.NotFound" { if len(describe.Addresses) > 0 {
return fmt.Errorf("Unexpected error: %s", err) return fmt.Errorf("still exists")
}
} }
} }