provider/aws: fix CheckDestroy on aws_instance tests

This commit is contained in:
Paul Hinze 2015-12-22 08:49:35 -06:00
parent 894e6cabbb
commit c8319d3b72
1 changed files with 10 additions and 11 deletions

View File

@ -540,27 +540,26 @@ 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 ae, ok := err.(awserr.Error); ok && ae.Code() == "InvalidInstanceID.NotFound" {
continue
}
if ec2err.Code() != "InvalidInstanceID.NotFound" {
return err
}
}
return nil
}