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.
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 liveonly 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.
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?
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.
First, terraform does a pretty good job in guaranteeing proper execution order for resources - using outputs of one resource as input for another and using explicit depends_on block. Since modules don’t have same sort of dependency mechanism, we usually use an extra dependencies input var to mimic that.
How we’re testing the modules / dependencies is through series of integration tests for each of our modules. A lot of the dependency issues are revealed during development and initial testing. Writing unit tests for IaC is very hard.