From 5a786d52d96a1f017db09f2dd7095821892d591b Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 1 Mar 2016 12:35:15 +0000 Subject: [PATCH 1/3] Fix: Do not store ID of CW Event Target if creation fails --- .../providers/aws/resource_aws_cloudwatch_event_target.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/builtin/providers/aws/resource_aws_cloudwatch_event_target.go b/builtin/providers/aws/resource_aws_cloudwatch_event_target.go index 727a17192..a64221f60 100644 --- a/builtin/providers/aws/resource_aws_cloudwatch_event_target.go +++ b/builtin/providers/aws/resource_aws_cloudwatch_event_target.go @@ -61,9 +61,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 +73,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) From dc45f84a8f37d4d316608b6612370712fef16664 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 1 Mar 2016 12:37:36 +0000 Subject: [PATCH 2/3] Allow recovering from failed CW Event Target creation in state --- .../aws/resource_aws_cloudwatch_event_target.go | 10 ++++++++++ 1 file changed, 10 insertions(+) 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) From 8ca732528c7b8787f88af6c9e1cc5a414640e5a5 Mon Sep 17 00:00:00 2001 From: Radek Simko Date: Tue, 1 Mar 2016 12:38:55 +0000 Subject: [PATCH 3/3] docs: CloudWatch Event Target expects role name (not ARN) --- .../docs/providers/aws/r/cloudwatch_event_target.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/docs/providers/aws/r/cloudwatch_event_target.html.markdown b/website/source/docs/providers/aws/r/cloudwatch_event_target.html.markdown index e7555da9b..20a94b31e 100644 --- a/website/source/docs/providers/aws/r/cloudwatch_event_target.html.markdown +++ b/website/source/docs/providers/aws/r/cloudwatch_event_target.html.markdown @@ -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}" }