Allow recovering from failed CW Event Target creation in state

This commit is contained in:
Radek Simko 2016-03-01 12:37:36 +00:00
parent 5a786d52d9
commit dc45f84a8f
1 changed files with 10 additions and 0 deletions

View File

@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform/helper/schema" "github.com/hashicorp/terraform/helper/schema"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
events "github.com/aws/aws-sdk-go/service/cloudwatchevents" events "github.com/aws/aws-sdk-go/service/cloudwatchevents"
) )
@ -94,6 +95,15 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface
d.SetId("") d.SetId("")
return nil return nil
} }
if awsErr, ok := err.(awserr.Error); ok {
// This should never happen, but it's useful
// for recovering from https://github.com/hashicorp/terraform/issues/5389
if awsErr.Code() == "ValidationException" {
log.Printf("[WARN] Removing CloudWatch Event Target %q because it never existed.", d.Id())
d.SetId("")
return nil
}
}
return err return err
} }
log.Printf("[DEBUG] Found Event Target: %s", t) log.Printf("[DEBUG] Found Event Target: %s", t)