resource/aws_batch_compute_environment: Retry delete on stale JobQueue relationship#46927
Open
quinnjr wants to merge 2 commits intohashicorp:mainfrom
Open
Conversation
…e relationship When a compute environment is replaced (create_before_destroy), the referencing job queue is updated to point to the new CE before the old one is deleted. Due to AWS Batch eventual consistency, the old CE may still show a job queue relationship when the delete is attempted, causing "Cannot delete, found existing JobQueue relationship". Wrap DeleteComputeEnvironment in tfresource.Retry to retry on this specific ClientException, matching the EKS cluster delete pattern. Fixes hashicorp#46925 Made-with: Cursor
Made-with: Cursor
Contributor
Community GuidelinesThis comment is added to every new Pull Request to provide quick reference to how the Terraform AWS Provider is maintained. Please review the information below, and thank you for contributing to the community that keeps the provider thriving! 🚀 Voting for Prioritization
Pull Request Authors
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Community Note
Description
When a
aws_batch_compute_environmentis replaced (viacreate_before_destroy/ PulumideleteBeforeReplace: false), the provider correctly:aws_batch_job_queueto point to the new CEStep 3 consistently fails with:
This happens because AWS Batch has eventual consistency — the job queue update returns success from the API, but the old CE still shows a job queue relationship when the delete is attempted moments later.
This PR wraps the
DeleteComputeEnvironmentcall intfresource.Retry, retrying on the specificClientExceptioncontaining"existing JobQueue relationship". This follows the same pattern used in the EKS cluster delete path forResourceInUseException(internal/service/eks/cluster.go).Affected Resource(s)
aws_batch_compute_environmentHow Has This Been Tested?
go build ./internal/service/batch/...)go vetpassesgo test ./internal/service/batch/... -run "TestExpand|TestFlatten")TestAccBatchComputeEnvironment_disappearscovers the delete pathBEST_FIT_PROGRESSIVEallocation strategy and a regular service role)AI Disclosure
AI assistance (Claude) was used to research the provider's retry patterns across other services (EKS, ECR, S3) and to draft the initial code structure. The fix was reviewed and validated by a human contributor who experienced the bug firsthand. All code has been read, understood, and verified.
References
Cannot deleteerror occurs whenaws_batch_compute_environmentused inaws_batch_job_queueis recreated #2044, Error while updating "aws_batch_compute_environment" #11077, Cannot alter AWS Compute Environment when Job Queue is still attached #11777 (earlier reports of the same problem)Made with Cursor