Terragrunt dependency Blocks: Wiring Units Together
A Terragrunt dependency block reads another unit outputs and makes that unit apply first in run-all.
dependency blocks are how Terragrunt stacks pass data between units (a VPC unit feeding subnet IDs to an EKS unit) while also defining the apply order for run-all.
What it does
A dependency "name" { config_path = "../other" } block fetches the outputs of the unit at config_path and exposes them as dependency.name.outputs.* in your inputs. It also adds an edge to the run-all DAG. mock_outputs supplies placeholder values so plan works before the dependency has been applied.
Common usage
dependency "vpc" {
config_path = "../vpc"
mock_outputs = {
vpc_id = "vpc-00000000"
subnet_ids = ["subnet-0000", "subnet-1111"]
}
mock_outputs_allowed_terraform_commands = ["plan", "validate"]
}
inputs = {
vpc_id = dependency.vpc.outputs.vpc_id
subnet_ids = dependency.vpc.outputs.subnet_ids
}Options
| Setting | What it does |
|---|---|
| config_path | Path to the unit whose outputs you consume |
| mock_outputs | Placeholder outputs used when real ones are unavailable |
| mock_outputs_allowed_terraform_commands | Commands allowed to use mocks (e.g. plan, validate) |
| skip_outputs | Add the DAG edge without reading outputs |
| dependencies { paths = [...] } | Order-only dependencies with no output passing |
In CI
On a brand-new environment, run-all plan cannot read outputs from un-applied units. Without mock_outputs, plan fails; with them, plan runs against placeholders and apply later uses the real values. Restrict mocks to plan/validate so a real apply never silently uses fake data.
Common errors in CI
"has not been applied yet. Please apply all of the dependencies" means a dependency has no outputs and no mock for the current command; add mock_outputs plus the command to mock_outputs_allowed_terraform_commands. "Detected a dependency cycle" means two units reference each other. "Cannot find config file in the given path" means config_path is wrong relative to the current unit.