Skip to content
Latchkey

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.

terragrunt
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

  1. Add a dependency block for each unit whose outputs you consume.
  2. Reference dependency.<name>.outputs.<value> in inputs.
  3. Re-run so Terragrunt orders the apply correctly.
terragrunt.hcl
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.

terragrunt.hcl
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 plan to confirm the graph before apply.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →