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/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"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -61,9 +62,6 @@ func resourceAwsCloudWatchEventTargetCreate(d *schema.ResourceData, meta interfa
|
||||||
rule := d.Get("rule").(string)
|
rule := d.Get("rule").(string)
|
||||||
targetId := d.Get("target_id").(string)
|
targetId := d.Get("target_id").(string)
|
||||||
|
|
||||||
id := rule + "-" + targetId
|
|
||||||
d.SetId(id)
|
|
||||||
|
|
||||||
input := buildPutTargetInputStruct(d)
|
input := buildPutTargetInputStruct(d)
|
||||||
log.Printf("[DEBUG] Creating CloudWatch Event Target: %s", input)
|
log.Printf("[DEBUG] Creating CloudWatch Event Target: %s", input)
|
||||||
out, err := conn.PutTargets(input)
|
out, err := conn.PutTargets(input)
|
||||||
|
@ -76,6 +74,9 @@ func resourceAwsCloudWatchEventTargetCreate(d *schema.ResourceData, meta interfa
|
||||||
out.FailedEntries)
|
out.FailedEntries)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
id := rule + "-" + targetId
|
||||||
|
d.SetId(id)
|
||||||
|
|
||||||
log.Printf("[INFO] CloudWatch Event Target %q created", d.Id())
|
log.Printf("[INFO] CloudWatch Event Target %q created", d.Id())
|
||||||
|
|
||||||
return resourceAwsCloudWatchEventTargetRead(d, meta)
|
return resourceAwsCloudWatchEventTargetRead(d, meta)
|
||||||
|
@ -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)
|
||||||
|
|
|
@ -15,7 +15,7 @@ Provides a CloudWatch Event Target resource.
|
||||||
```
|
```
|
||||||
resource "aws_cloudwatch_event_target" "yada" {
|
resource "aws_cloudwatch_event_target" "yada" {
|
||||||
target_id = "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}"
|
arn = "${aws_kinesis_stream.test_stream.arn}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue