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

Sweeper fixes #37130

Merged
merged 5 commits into from
Apr 26, 2024
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
4 changes: 4 additions & 0 deletions .changelog/37130.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

```release-note:enhancement
resource/aws_cloudwatch_event_target: Add `force_destroy` argument
```
11 changes: 5 additions & 6 deletions internal/service/events/rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions internal/service/events/sweep.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down Expand Up @@ -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)

Expand Down
26 changes: 19 additions & 7 deletions internal/service/events/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)...)
Expand All @@ -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)

Expand Down
Loading
Loading