Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

provider/aws: Allow recovering from failed CloudWatch Event Target creation #5395

Merged
merged 3 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions builtin/providers/aws/resource_aws_cloudwatch_event_target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -61,9 +62,6 @@ func resourceAwsCloudWatchEventTargetCreate(d *schema.ResourceData, meta interfa
rule := d.Get("rule").(string)
targetId := d.Get("target_id").(string)

id := rule + "-" + targetId
d.SetId(id)

input := buildPutTargetInputStruct(d)
log.Printf("[DEBUG] Creating CloudWatch Event Target: %s", input)
out, err := conn.PutTargets(input)
Expand All @@ -76,6 +74,9 @@ func resourceAwsCloudWatchEventTargetCreate(d *schema.ResourceData, meta interfa
out.FailedEntries)
}

id := rule + "-" + targetId
d.SetId(id)

log.Printf("[INFO] CloudWatch Event Target %q created", d.Id())

return resourceAwsCloudWatchEventTargetRead(d, meta)
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Provides a CloudWatch Event Target resource.
```
resource "aws_cloudwatch_event_target" "yada" {
target_id = "Yada"
rule = "${aws_cloudwatch_event_rule.console.arn}"
rule = "${aws_cloudwatch_event_rule.console.name}"
arn = "${aws_kinesis_stream.test_stream.arn}"
}

Expand Down