From 0ae4d86b812e78c610e7d6c741548bd6891554a8 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 26 Apr 2024 08:30:02 -0400 Subject: [PATCH 1/5] sweepers: Skip 'UnknownOperationException: Operation is disabled in this region' errors (e.g. GovCloud). --- internal/sweep/awsv2/skip.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/internal/sweep/awsv2/skip.go b/internal/sweep/awsv2/skip.go index b779fad67c12..d9ec756eb5de 100644 --- a/internal/sweep/awsv2/skip.go +++ b/internal/sweep/awsv2/skip.go @@ -41,6 +41,10 @@ func SkipSweepError(err error) bool { if tfawserr.ErrMessageContains(err, "InvalidParameterValueException", "Access Denied to API Version") { return true } + // Example (GovCloud): UnknownOperationException: Operation is disabled in this region + if tfawserr.ErrMessageContains(err, "UnknownOperationException", "Operation is disabled in this region") { + return true + } return false } From a9ae479803c60c1aaf6b58bebc5d73d3d0da25d2 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 26 Apr 2024 08:50:38 -0400 Subject: [PATCH 2/5] r/aws_cloudwatch_event_target: Add `force_destroy` argument. --- .changelog/#####.txt | 4 + internal/service/events/rule.go | 11 +- internal/service/events/target.go | 26 ++- internal/service/events/target_test.go | 242 ++++++++++++++----------- 4 files changed, 163 insertions(+), 120 deletions(-) create mode 100644 .changelog/#####.txt diff --git a/.changelog/#####.txt b/.changelog/#####.txt new file mode 100644 index 000000000000..aaaab0a092ca --- /dev/null +++ b/.changelog/#####.txt @@ -0,0 +1,4 @@ + +```release-note:enhancement +resource/aws_cloudwatch_event_target: Add `force_destroy` argument +``` \ No newline at end of file diff --git a/internal/service/events/rule.go b/internal/service/events/rule.go index e96a1bafd143..b2d2883c6b9f 100644 --- a/internal/service/events/rule.go +++ b/internal/service/events/rule.go @@ -251,7 +251,7 @@ func resourceRuleUpdate(ctx context.Context, d *schema.ResourceData, meta interf var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EventsClient(ctx) - if d.HasChangesExcept("tags", "tags_all") { + if d.HasChangesExcept("tags", "tags_all", "force_destroy") { _, ruleName, err := ruleParseResourceID(d.Id()) if err != nil { return sdkdiag.AppendFromErr(diags, err) @@ -282,15 +282,14 @@ func resourceRuleDelete(ctx context.Context, d *schema.ResourceData, meta interf Name: aws.String(ruleName), } - forceDestroy := d.Get("force_destroy").(bool) - if forceDestroy { - input.Force = forceDestroy - } - if eventBusName != "" { input.EventBusName = aws.String(eventBusName) } + if v, ok := d.GetOk("force_destroy"); ok { + input.Force = v.(bool) + } + const ( timeout = 5 * time.Minute ) diff --git a/internal/service/events/target.go b/internal/service/events/target.go index 4af36729ee06..58185df424f0 100644 --- a/internal/service/events/target.go +++ b/internal/service/events/target.go @@ -254,6 +254,11 @@ func resourceTarget() *schema.Resource { ValidateFunc: validBusNameOrARN, Default: DefaultEventBusName, }, + "force_destroy": { + Type: schema.TypeBool, + Optional: true, + Default: false, + }, "http_target": { Type: schema.TypeList, Optional: true, @@ -541,6 +546,7 @@ func resourceTargetRead(ctx context.Context, d *schema.ResourceData, meta interf d.Set("arn", target.Arn) d.Set("event_bus_name", eventBusName) + d.Set("force_destroy", d.Get("force_destroy").(bool)) d.Set("input", target.Input) d.Set("input_path", target.InputPath) d.Set("role_arn", target.RoleArn) @@ -621,16 +627,18 @@ func resourceTargetUpdate(ctx context.Context, d *schema.ResourceData, meta inte var diags diag.Diagnostics conn := meta.(*conns.AWSClient).EventsClient(ctx) - input := expandPutTargetsInput(ctx, d) + if d.HasChangesExcept("force_destroy") { + input := expandPutTargetsInput(ctx, d) - output, err := conn.PutTargets(ctx, input) + output, err := conn.PutTargets(ctx, input) - if err == nil && output != nil { - err = putTargetsError(output.FailedEntries) - } + if err == nil && output != nil { + err = putTargetsError(output.FailedEntries) + } - if err != nil { - return sdkdiag.AppendErrorf(diags, "updating EventBridge Target (%s): %s", d.Id(), err) + if err != nil { + return sdkdiag.AppendErrorf(diags, "updating EventBridge Target (%s): %s", d.Id(), err) + } } return append(diags, resourceTargetRead(ctx, d, meta)...) @@ -649,6 +657,10 @@ func resourceTargetDelete(ctx context.Context, d *schema.ResourceData, meta inte input.EventBusName = aws.String(v.(string)) } + if v, ok := d.GetOk("force_destroy"); ok { + input.Force = v.(bool) + } + log.Printf("[DEBUG] Deleting EventBridge Target: %s", d.Id()) output, err := conn.RemoveTargets(ctx, input) diff --git a/internal/service/events/target_test.go b/internal/service/events/target_test.go index 42c1f724c7b5..16adb6f7ee1f 100644 --- a/internal/service/events/target_test.go +++ b/internal/service/events/target_test.go @@ -228,16 +228,18 @@ func TestAccEventsTarget_basic(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetNoBusNameImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetNoBusNameImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_defaultBusName(rName), @@ -293,10 +295,11 @@ func TestAccEventsTarget_eventBusName(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -328,10 +331,11 @@ func TestAccEventsTarget_eventBusARN(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -361,10 +365,11 @@ func TestAccEventsTarget_generatedTargetID(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -399,10 +404,11 @@ func TestAccEventsTarget_RetryPolicy_deadLetter(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -435,10 +441,11 @@ func TestAccEventsTarget_full(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -467,10 +474,11 @@ func TestAccEventsTarget_ssmDocument(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -502,10 +510,11 @@ func TestAccEventsTarget_http(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -539,10 +548,11 @@ func TestAccEventsTarget_http_params(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_httpParameterUpdated(rName), @@ -592,10 +602,11 @@ func TestAccEventsTarget_ecs(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -624,10 +635,11 @@ func TestAccEventsTarget_redshift(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -664,10 +676,11 @@ func TestAccEventsTarget_ecsWithoutLaunchType(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_ecs(rName), @@ -677,10 +690,11 @@ func TestAccEventsTarget_ecsWithoutLaunchType(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_ecsNoLaunchType(rName), @@ -725,10 +739,11 @@ func TestAccEventsTarget_ecsWithBlankLaunchType(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_ecs(rName), @@ -738,10 +753,11 @@ func TestAccEventsTarget_ecsWithBlankLaunchType(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, { Config: testAccTargetConfig_ecsBlankLaunchType(rName), @@ -775,10 +791,11 @@ func TestAccEventsTarget_ecsWithBlankTaskCount(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -813,10 +830,11 @@ func TestAccEventsTarget_ecsFull(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -847,10 +865,11 @@ func TestAccEventsTarget_ecsCapacityProvider(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -882,10 +901,11 @@ func TestAccEventsTarget_ecsPlacementStrategy(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -914,10 +934,11 @@ func TestAccEventsTarget_batch(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -944,9 +965,11 @@ func TestAccEventsTarget_kinesis(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -973,10 +996,11 @@ func TestAccEventsTarget_sqs(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -1008,10 +1032,11 @@ func TestAccEventsTarget_sageMakerPipeline(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -1066,10 +1091,11 @@ func TestAccEventsTarget_Input_transformer(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -1131,10 +1157,11 @@ func TestAccEventsTarget_partnerEventBus(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) @@ -1163,10 +1190,11 @@ func TestAccEventsTarget_ecsNoPropagateTags(t *testing.T) { ), }, { - ResourceName: resourceName, - ImportState: true, - ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), - ImportStateVerify: true, + ResourceName: resourceName, + ImportState: true, + ImportStateIdFunc: testAccTargetImportStateIdFunc(resourceName), + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{"force_destroy"}, }, }, }) From f145283c72b15122ee157c2101dc17fb28005eef Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 26 Apr 2024 08:51:36 -0400 Subject: [PATCH 3/5] r/aws_cloudwatch_event_target: Set 'force_destroy' to 'true' in sweeper. --- internal/service/events/sweep.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/service/events/sweep.go b/internal/service/events/sweep.go index 1402645a8db0..be8ea22b4a02 100644 --- a/internal/service/events/sweep.go +++ b/internal/service/events/sweep.go @@ -279,6 +279,7 @@ func sweepRules(region string) error { r := resourceRule() d := r.Data(nil) d.SetId(ruleCreateResourceID(eventBusName, ruleName)) + d.Set("force_destroy", true) sweepResources = append(sweepResources, sweep.NewSweepResource(r, d, client)) } @@ -357,6 +358,7 @@ func sweepTargets(region string) error { d := r.Data(nil) d.SetId(targetCreateResourceID(eventBusName, ruleName, targetID)) d.Set("event_bus_name", eventBusName) + d.Set("force_destroy", true) d.Set("rule", ruleName) d.Set("target_id", targetID) From a057c69674302ab2a88cab202636e879409f824e Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 26 Apr 2024 13:31:53 -0400 Subject: [PATCH 4/5] Correct CHANGELOG entry file name. --- .changelog/{#####.txt => 37130.txt} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .changelog/{#####.txt => 37130.txt} (100%) diff --git a/.changelog/#####.txt b/.changelog/37130.txt similarity index 100% rename from .changelog/#####.txt rename to .changelog/37130.txt From 7bbed303ad35ce0ce06303878f1527e27828c945 Mon Sep 17 00:00:00 2001 From: Kit Ewbank Date: Fri, 26 Apr 2024 13:34:52 -0400 Subject: [PATCH 5/5] Update documentation. --- website/docs/r/cloudwatch_event_target.html.markdown | 1 + 1 file changed, 1 insertion(+) diff --git a/website/docs/r/cloudwatch_event_target.html.markdown b/website/docs/r/cloudwatch_event_target.html.markdown index cd466439909c..82d2cf9b2468 100644 --- a/website/docs/r/cloudwatch_event_target.html.markdown +++ b/website/docs/r/cloudwatch_event_target.html.markdown @@ -468,6 +468,7 @@ The following arguments are optional: * `ecs_target` - (Optional) Parameters used when you are using the rule to invoke Amazon ECS Task. Documented below. A maximum of 1 are allowed. * `event_bus_name` - (Optional) The name or ARN of the event bus to associate with the rule. If you omit this, the `default` event bus is used. +* `force_destroy` - (Optional) Used to delete managed rules created by AWS. Defaults to `false`. * `http_target` - (Optional) Parameters used when you are using the rule to invoke an API Gateway REST endpoint. Documented below. A maximum of 1 is allowed. * `input` - (Optional) Valid JSON text passed to the target. Conflicts with `input_path` and `input_transformer`. * `input_path` - (Optional) The value of the [JSONPath](http://goessner.net/articles/JsonPath/) that is used for extracting part of the matched event when passing it to the target. Conflicts with `input` and `input_transformer`.