From fe0e8da3dd33f778c954a9f7c65d4b7b322ab035 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Sun, 13 Mar 2016 10:28:14 +0000 Subject: [PATCH] provider/aws: Handle deleted CloudFormation stack gracefully --- .../aws/resource_aws_cloudformation_stack.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/builtin/providers/aws/resource_aws_cloudformation_stack.go b/builtin/providers/aws/resource_aws_cloudformation_stack.go index 56249587b..1b767ddce 100644 --- a/builtin/providers/aws/resource_aws_cloudformation_stack.go +++ b/builtin/providers/aws/resource_aws_cloudformation_stack.go @@ -191,12 +191,20 @@ func resourceAwsCloudFormationStackRead(d *schema.ResourceData, meta interface{} } resp, err := conn.DescribeStacks(input) if err != nil { + awsErr, ok := err.(awserr.Error) + // ValidationError: Stack with id % does not exist + if ok && awsErr.Code() == "ValidationError" { + log.Printf("[WARN] Removing CloudFormation stack %s as it's already gone", d.Id()) + d.SetId("") + return nil + } + return err } stacks := resp.Stacks if len(stacks) < 1 { - log.Printf("[DEBUG] Removing CloudFormation stack %s as it's already gone", d.Id()) + log.Printf("[WARN] Removing CloudFormation stack %s as it's already gone", d.Id()) d.SetId("") return nil } @@ -406,6 +414,7 @@ func resourceAwsCloudFormationStackDelete(d *schema.ResourceData, meta interface log.Printf("[DEBUG] Error when deleting CloudFormation stack: %s: %s", awsErr.Code(), awsErr.Message()) + // ValidationError: Stack with id % does not exist if awsErr.Code() == "ValidationError" { return resp, "DELETE_COMPLETE", nil }