Merge pull request #5395 from TimeIncOSS/b-cw-even-target-role
provider/aws: Allow recovering from failed CloudWatch Event Target creation
This commit is contained in:
commit
528bad36ff
|
@ -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"
|
||||
)
|
||||
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
|
|
@ -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}"
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue