terraform-aws-modules / terraform-aws-batch

Terraform module to create AWS Batch resources 🇺🇦
https://registry.terraform.io/modules/terraform-aws-modules/batch/aws
Apache License 2.0
35 stars 40 forks source link

fix: Add `create_before_destroy` lifecycle hook to `aws_batch_compute_environment` #18

Closed thatarchguy closed 1 year ago

thatarchguy commented 1 year ago

Description

Solves https://github.com/terraform-aws-modules/terraform-aws-batch/issues/5. Also discussed in this stackoverflow question: https://stackoverflow.com/questions/61669156/terraform-how-to-enable-deletion-of-batch-service-compute-environment

Motivation and Context

After applying and then making changes to the terraform, I am met with this error:


Error: deleting Batch Compute Environment (ec2_spot-20230302161118607200000001): : Cannot delete, found existing JobQueue relationship.
    status code: 400, request id: d1174a9c-525b-45d5-8b4e-6830ea7a7246

No jobs are in the queue. This error is due to a dependency issue and is solved with this lifecycle hook. To quote the stackoverflow answer:

When a resource is recreated in Terraform, it will be deleted and created in order by default. So if compute_environment_nameyou change and apply only, the computing environment on which the job queue depends temporarily does not exist, so you will die as follows. Error: Error applying plan:[...] Therefore, compute_environment_namechange create_before_destroy = trueand specify the lifecycle explicitly.

Breaking Changes

None

How Has This Been Tested?

antonbabenko commented 1 year ago

This PR is included in version 1.2.3 :tada:

github-actions[bot] commented 1 year ago

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.