Skip to content

Commit

Permalink
aws: Treat CF stacks in DELETE_COMPLETE state as deleted
Browse files Browse the repository at this point in the history
  • Loading branch information
radeksimko committed Dec 17, 2015
1 parent 08ad2d2 commit f017d2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
10 changes: 10 additions & 0 deletions builtin/providers/aws/resource_aws_cloudformation_stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,18 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{}

stacks := resp.Stacks
if len(stacks) < 1 {
log.Printf("[DEBUG] Removing CloudFormation stack %s as it's already gone", d.Id())
d.SetId("")
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{
StackName: aws.String(stackName),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,12 @@ func testAccCheckAWSCloudFormationDestroy(s *terraform.State) error {

resp, err := conn.DescribeStacks(&params)

if err == nil {
if len(resp.Stacks) != 0 &&
*resp.Stacks[0].StackId == rs.Primary.ID {
if err != nil {
return err
}

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)
}
}
Expand Down

0 comments on commit f017d2d

Please sign in to comment.