From 10cc513ae03975d1c0010e83f6423a3c7aaa087b Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Tue, 22 Dec 2015 07:34:06 -0600 Subject: [PATCH] provider/aws: fix CheckDestroy for aws_eip tests --- .../providers/aws/resource_aws_eip_test.go | 46 ++++++++++++------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/builtin/providers/aws/resource_aws_eip_test.go b/builtin/providers/aws/resource_aws_eip_test.go index e93e002f7..56955a8c1 100644 --- a/builtin/providers/aws/resource_aws_eip_test.go +++ b/builtin/providers/aws/resource_aws_eip_test.go @@ -86,26 +86,38 @@ func testAccCheckAWSEIPDestroy(s *terraform.State) error { continue } - req := &ec2.DescribeAddressesInput{ - PublicIps: []*string{aws.String(rs.Primary.ID)}, - } - describe, err := conn.DescribeAddresses(req) - - if err == nil { - if len(describe.Addresses) != 0 && - *describe.Addresses[0].PublicIp == rs.Primary.ID { - return fmt.Errorf("EIP still exists") + if strings.Contains(rs.Primary.ID, "eipalloc") { + req := &ec2.DescribeAddressesInput{ + AllocationIds: []*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 } - } - // Verify the error - providerErr, ok := err.(awserr.Error) - if !ok { - return err - } + if len(describe.Addresses) > 0 { + return fmt.Errorf("still exists") + } + } 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" { - return fmt.Errorf("Unexpected error: %s", err) + if len(describe.Addresses) > 0 { + return fmt.Errorf("still exists") + } } }