Closed rmgpinto closed 3 years ago
Hi @rmgpinto,
Thanks for filing the issue. Modules in terraform are not isolated in the way you are describing here, they are logical groupings of configurations but terraform is still free to perform resource actions concurrently when possible. It is always preferable to pass the desired data between modules and allow terraform to order all resources individually than to use depends_on
and try to force the ordering of modules as a whole.
When managed resources are destroyed, the ordering is defined by the dependencies they had when they were created or last updated. This means that the depends_on
references here should add the desired dependencies for the correct destroy ordering. Since being able to destroy resources should not be effected by the usage of modules or depends_on
, this may be failing in other ways.
I would first verify that the configuration can be reliably destroyed without using the -target
flag. If that does work, perhaps there is some transitive dependency which is being dropped with the use of targeting.
If the configuration cannot be reliably destroyed in any case, then it is more likely a mis-configuration within the modules themselves, and my first guess would be that some resources require create_before_destroy
and are missing that in their configuration.
In either case, it would be helpful to have a minimal reproducible example to work with here, so that we can see how the configuration is structured, and what happens when the destroy operation fails.
Thanks!
Since we have not heard back in a while I'm going to close the issue. If you have any updates about the problem, feel free to open a new issue with the requested information. If you have more questions, you can also use the community forum where there are more people ready to help.
Thanks!
I'm going to lock this issue 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 similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Terraform Version
Terraform Configuration Files
Expected Behavior
We have a kops cluster and on top of that there are multiple apps. In particular we have an
aws-load-balancer-controller
module that creates ALB load balancers and target groups automatically. When I try toterraform destroy -target module.kops
, both modules are destroyed simultaneously and thedepends_on
is not followed by terraform on the destroy order. I was expecting the moduledoorman
to be completely destroyed before starting the destroy on theaws-load-balancer-controller
. This behavior is leaving dangling AWS load balancers and target groups, which don't get destroyed properly byaws-load-balancer-controller
, because this module is destroyed before it can delete correctly the resources.Actual Behavior
Terraform is destroying both modules in parallel and we have to manually destroy resources on AWS.
Steps to Reproduce
terraform destroy -target module.kops