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

(Re)run terragrunt run-all destroy even if some resources tore down successfully while others failed #3183

Open
2 tasks
karlschriek opened this issue Jun 5, 2024 · 4 comments
Assignees
Labels
bug Something isn't working terragrunt

Comments

@karlschriek
Copy link

karlschriek commented Jun 5, 2024

Describe the bug

I am currently evaluating terragrunt's run-all capabilities and am getting unstuck on the terragrunt run-all destroy, in particular in the case of failure. I am not able to simply rerun this command if some modules destroyed correctly, but others failed. Let's say for example that terragrunt run-all apply generates the following dependency graph:

Group 1
- Module /root/myproject/base

Group 2
- Module /root/myproject/module1
- Module /root/myproject/module2

Group 3
- Module /root/myproject/module1_extension

Above both "module1" and "module2" depend on "base"; "module1_extension" depends on "module1".

In this case terragrunt run-all destroy will destroy all the "Group 3" modules, then the "Group 2" modules, then the "Group 1" modules. In the case where it successfully tears down both "Group 3" and "Group 2", but fails to fully remove "Group 1" I was hoping to be able to just again run terragrunt run-all destroy, but this does not work, erroring out with:

ERRO[0004] Module /root/myproject/module1_extension has finished with an error: /root/myproject/module1/terragrunt.hcl is a dependency of /root/myproject/module1_extension/terragrunt.hcl but detected no outputs. Either the target module has not been applied yet, or the module has no outputs. If this is expected, set the skip_outputs flag to true on the dependency block.  prefix=[/root/myproject/module1_extension]

Steps To Reproduce

Steps to reproduce the behavior, code snippets and examples which can be used to reproduce the issue.

Create a project structure as above and then destroy module1, module2 and module1_extension. If you now try to run "terragrunt run-all destroy" you will get the above error. (You can also just apply "module1" to begin with and then "run-all destroy")

Expected behavior

To be clear, in this specific example only the "base" project still needs to be torn down (everything else is gone). I could tear it down now with --terragrunt-include-dir *base, but since errors in destroy steps are quite common I would expect terragrunt to be able to deal with repeating the command to destroy all. Since destroy happens sequentially (in a reverse order to apply), terragrunt should know which states have been torn down and which haven't and should always be able to retry the ones that are still there (since, unless you specified --terragrunt-ignore-dependency-errors, it would not have gone on and torn down modules that anything that hasn't been torn down yet depends on).

EDIT: I am not entirely sure about the "unless you specified --terragrunt-ignore-dependency-errors" part. Would terragrunt go ahead and destroy "module1" even if "module1_extension" failed to destroy correctly with --terragrunt-ignore-dependency-errors set? Because if it still respects that dependency then just setting that flag is probably the solution to this post (although somewhat messy and full of irrelevant warnings).

Nice to haves

  • Terminal output
  • Screenshots

Versions

  • Terragrunt version: 0.58.10
  • OpenTofu/Terraform version: tf 1.8.3
  • Environment details (Ubuntu 20.04, Windows 10, etc.):

Additional context

Add any other context about the problem here.

@karlschriek karlschriek added the bug Something isn't working label Jun 5, 2024
@ZachGoldberg ZachGoldberg added the terragrunt label Jun 11, 2024 — with Linear
@denis256
Copy link
Member

Hello,
Terragrunt is simply the runner of Terraform and doesn't have transactional capabilities to execute all or nothing, once dependency was destroyed, outputs reading will not work.

It can be also used --terragrunt-strict-include and specify path to specific depdencnies to use them in destroy
https://terragrunt.gruntwork.io/docs/reference/cli-options/#terragrunt-strict-include

@karlschriek
Copy link
Author

karlschriek commented Jun 12, 2024 via email

@denis256
Copy link
Member

Hello,
in the current implementation, Terrgrunt "doesn't know" what was already destroyed and if the module should be skipped or not, so it is trying to do destroy each time.

@karlschriek
Copy link
Author

karlschriek commented Jun 12, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working terragrunt
Projects
None yet
Development

No branches or pull requests

3 participants