Dependencies & outputs
Wire modules together safely.
Separate state units need to share data — the app unit needs the vpc unit’s subnet IDs, the database unit’s endpoint. Terragrunt’s dependency block reads another unit’s Terraform outputs and exposes them, and in doing so declares an ordering edge: Terragrunt knows the app depends on the vpc and will apply them in the right order under run-all. This replaces fragile remote-state data sources with a first-class dependency graph.
dependency "vpc" {config_path = "../vpc"mock_outputs = { # used during plan when vpc isn’t applied yetvpc_id = "vpc-mock"subnet_ids = ["subnet-mock"]}}inputs = {vpc_id = dependency.vpc.outputs.vpc_idsubnet_ids = dependency.vpc.outputs.subnet_ids}
Mock outputs for planning
A dependency’s real outputs only exist once that unit is applied, which breaks planning a brand-new environment where nothing is applied yet. mock_outputs supply placeholder values so a plan can run before the dependency exists — essential for run-all plan on a fresh stack. The mocks are for planning only; the real outputs are used at apply. Getting mocks right is what lets you plan a whole environment from scratch.
$ terragrunt output -raw vpc_id # a single unit’s output# under run-all, Terragrunt applies vpc before app automatically because of the dependency