Terragrunt run-all apply ordering / dependency errors in CI
Terragrunt builds the run-all execution order from dependency and dependencies blocks. If a unit does not declare a dependency it actually needs, run-all may apply it before the resource it consumes exists, so it fails on a missing input or a not-yet-created resource.
What this error means
A run-all apply fails because a unit ran before its prerequisite, referencing an output or resource (a VPC id, a subnet) that has not been created yet.
ERRO[0007] [live/prod/app] Error: Reference to undeclared resource / value not known:
the VPC id from live/prod/vpc was expected but that unit had not been applied first.
Terragrunt applied units in an order that did not satisfy an undeclared dependency.Common causes
A needed dependency block is missing
The consuming unit reads a value from another unit but does not declare a dependency on it, so Terragrunt does not order them correctly.
An implicit resource ordering was assumed
Two units share infrastructure but rely on run order alone; without a declared dependency, parallel run-all does not guarantee it.
How to fix it
Declare the dependency explicitly
- Add a
dependencyblock for each unit whose outputs you consume. - Reference
dependency.<name>.outputs.<value>in inputs. - Re-run so Terragrunt orders the apply correctly.
dependency "vpc" {
config_path = "../vpc"
}
inputs = { vpc_id = dependency.vpc.outputs.vpc_id }Add an ordering-only dependency
When you need order but not outputs, use the dependencies block to force sequencing.
dependencies {
paths = ["../vpc", "../iam"]
}How to prevent it
- Declare a dependency for every cross-unit value you consume.
- Use
dependencies { paths = [...] }for pure ordering needs. - Run
run-all planto confirm the graph before apply.