terragrunt icon indicating copy to clipboard operation
terragrunt copied to clipboard

Terragrunt should check dependencies on every command

Open brikis98 opened this issue 6 years ago • 1 comments

Terragrunt supports apply-all and destroy-all commands for working with multiple modules. Since one module can depend on another module, you can specify a list of dependencies in your Terragrunt configuration to ensure they are applied in the correct order.

Currently, these dependencies are only checked when you call a xxx-all command, and ignored for all other commands. This makes it easy for those lists of dependencies to go out of date.

Terragrunt should probably verify dependencies for every command. For backwards compatibility, we may want to have it off by default initially, and allow you to enable it in your Terragrunt config (e.g., check_dependencies = true) and via CLI param (e.g., --terragrunt-check-dependencies). In a few releases, we may turn it on by default.

brikis98 avatar Aug 26 '17 16:08 brikis98

#1927 appears related as well.

Output of terragrunt run-all destroy and terragrunt destroy should be consistent, that includes the dependency calculation. The two are too closely related to be giving different outputs.

Here is an example from our environment:

02-vips  $ terragrunt run-all destroy
INFO[0000] The stack at /xyz/02-vips will be processed in the following order for command destroy:
Group 1
- Module /xyz/02-vips

WARNING: Are you sure you want to run `terragrunt destroy` in each folder of the stack described above?
There is no undo! (y/n)
02-vips  $ terragrunt destroy
Detected dependent modules:
/xyz/03-infra
WARNING: Are you sure you want to continue? (y/n)

The next logical step here would be to make sure that terragrunt run-all destroy tears down, sequentially from last to first, the modules that depend on it. So, if we have the following dependency tree:

m03 -> m02 -> m01 Meaning, that m03 depends on m02 and m01, and m02 depends on m01.

Then (run-all apply) m03 $ terragrunt run-all apply Should warn, prompt, then stand up m01, then m02, then m03.

AND (run-all destroy)

$ cd ../m01
m01 $ terragrunt run-all destroy`

Should warn, prompt, then destroy m03, then m02, then m01.

I just tested this with v0.37.1

ttudre977 avatar Jun 06 '22 19:06 ttudre977