diff --git a/builtin/providers/aws/resource_aws_cloudwatch_event_target.go b/builtin/providers/aws/resource_aws_cloudwatch_event_target.go index a64221f60..031090c5b 100644 --- a/builtin/providers/aws/resource_aws_cloudwatch_event_target.go +++ b/builtin/providers/aws/resource_aws_cloudwatch_event_target.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/schema" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/awserr" events "github.com/aws/aws-sdk-go/service/cloudwatchevents" ) @@ -94,6 +95,15 @@ func resourceAwsCloudWatchEventTargetRead(d *schema.ResourceData, meta interface d.SetId("") 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 } log.Printf("[DEBUG] Found Event Target: %s", t)