Skip to content
Open
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
3 changes: 3 additions & 0 deletions .changelog/46927.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
resource/aws_batch_compute_environment: Fix `Cannot delete, found existing JobQueue relationship` error during replacement by retrying deletion with backoff
```
22 changes: 21 additions & 1 deletion internal/service/batch/compute_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -569,7 +569,27 @@ func resourceComputeEnvironmentDelete(ctx context.Context, d *schema.ResourceDat
deleteInput := batch.DeleteComputeEnvironmentInput{
ComputeEnvironment: aws.String(d.Id()),
}
_, err = conn.DeleteComputeEnvironment(ctx, &deleteInput)

// Retry the delete because AWS Batch has eventual consistency for job queue
// disassociation. When a compute environment is being replaced
// (create_before_destroy), the referencing job queue is updated to point to
// the new compute environment before the old one is deleted. However, the
// relationship may not have propagated yet, causing the delete to fail with
// "Cannot delete, found existing JobQueue relationship".
// See: https://github.com/hashicorp/terraform-provider-aws/issues/46925
err = tfresource.Retry(ctx, d.Timeout(schema.TimeoutDelete), func(ctx context.Context) *tfresource.RetryError {
_, err := conn.DeleteComputeEnvironment(ctx, &deleteInput)

if errs.IsAErrorMessageContains[*awstypes.ClientException](err, "existing JobQueue relationship") {
return tfresource.RetryableError(err)
}

if err != nil {
return tfresource.NonRetryableError(err)
}

return nil
}, tfresource.WithDelayRand(1*time.Minute), tfresource.WithPollInterval(30*time.Second))

if err != nil {
return sdkdiag.AppendErrorf(diags, "deleting Batch Compute Environment (%s): %s", d.Id(), err)
Expand Down
Loading