From c8319d3b7248ea50336e5352e1dfe3a43c5fe8a6 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Tue, 22 Dec 2015 08:49:35 -0600 Subject: [PATCH] provider/aws: fix CheckDestroy on aws_instance tests --- .../aws/resource_aws_instance_test.go | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/builtin/providers/aws/resource_aws_instance_test.go b/builtin/providers/aws/resource_aws_instance_test.go index 23c1e7b38..9b1e3b8e7 100644 --- a/builtin/providers/aws/resource_aws_instance_test.go +++ b/builtin/providers/aws/resource_aws_instance_test.go @@ -540,26 +540,25 @@ func testAccCheckInstanceDestroyWithProvider(s *terraform.State, provider *schem } // Try to find the resource - var err error resp, err := conn.DescribeInstances(&ec2.DescribeInstancesInput{ InstanceIds: []*string{aws.String(rs.Primary.ID)}, }) if err == nil { - if len(resp.Reservations) > 0 { - return fmt.Errorf("still exist.") + for _, r := range resp.Reservations { + for _, i := range r.Instances { + if i.State != nil && *i.State.Name != "terminated" { + return fmt.Errorf("Found unterminated instance: %s", i) + } + } } - - return nil } // Verify the error is what we want - ec2err, ok := err.(awserr.Error) - if !ok { - return err - } - if ec2err.Code() != "InvalidInstanceID.NotFound" { - return err + if ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidInstanceID.NotFound" { + continue } + + return err } return nil