Handling dependencies

Hi, I’m trying to understand how to best manage dependencies. I read this section: https://github.com/gruntwork-io/terragrunt#dependencies-between-modules, but I’m not clear on whether the dependencies block should go in terraform.hcl’s in my “live” or “modules” repository.

Also, I’m trying to understand the pros/cons of this approach vs having your ‘live’ setup explicitly link say an input of module B to an output of module A such that Terraform’s dependency management handles this automagically.

Hi,

The dependencies should be in your terragrunt.hcl. The dependencies main purpose is to guarantee correct execution order when you’re applying or destroying infrastructure with the *-all -commands.

Normally your live only contains the terragrunt.hcl for passing variables into your infrastructure-modules. The modules is where you use the outputs and the terraform dependency hierarchy - which is a bit different from the terragrunt.hcl dependency declaration.

Hope this clarifies the issue!

/Petri

Hello @autero1, i have similar question.
So i have put the dependency part in my terragrunt.hcl in lets call it Live structure. And when i do plan-all i can see that it says some of the section has a dependency.
How to handle if that is even possible the case when we are using data.terraform_remote_state from one module into another and we are running everything for the first time, obviously there are no state file for the first module, no outputs, so it cant use it on the second, and plan fails. So does this mean that we have to create VPC module first on its own so there is state file from which to pick the outputs and only then create all the others?

Thanks

Hi @Cvijan_Uros,

The plan-all will fail as expected, because the remote state does not exist. However, provided that you have specified your dependencies correctly, apply-all will succeed, because the changes will be applied in dependency order.

Hi,

Thanks for the quick answer, i will try it out.

Best regards,