aws: Treat CF stacks in DELETE_COMPLETE state as deleted

This commit is contained in:
Radek Simko 2015-12-17 17:58:11 +01:00
parent 08ad2d2d7e
commit f017d2d2d6
2 changed files with 16 additions and 3 deletions

View File

@ -190,8 +190,18 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{}
stacks := resp.Stacks stacks := resp.Stacks
if len(stacks) < 1 { if len(stacks) < 1 {
log.Printf("[DEBUG] Removing CloudFormation stack %s as it's already gone", d.Id())
d.SetId("")
return nil return nil
} }
for _, s := range stacks {
if *s.StackId == d.Id() && *s.StackStatus == "DELETE_COMPLETE" {
log.Printf("[DEBUG] Removing CloudFormation stack %s"+
" as it has been already deleted", d.Id())
d.SetId("")
return nil
}
}
tInput := cloudformation.GetTemplateInput{ tInput := cloudformation.GetTemplateInput{
StackName: aws.String(stackName), StackName: aws.String(stackName),

View File

@ -101,9 +101,12 @@ func testAccCheckAWSCloudFormationDestroy(s *terraform.State) error {
resp, err := conn.DescribeStacks(&params) resp, err := conn.DescribeStacks(&params)
if err == nil { if err != nil {
if len(resp.Stacks) != 0 && return err
*resp.Stacks[0].StackId == rs.Primary.ID { }
for _, s := range resp.Stacks {
if *s.StackId == rs.Primary.ID && *s.StackStatus != "DELETE_COMPLETE" {
return fmt.Errorf("CloudFormation stack still exists: %q", rs.Primary.ID) return fmt.Errorf("CloudFormation stack still exists: %q", rs.Primary.ID)
} }
} }