Error: Can't evaluate expression - The local reference is not evaluated
Fixes Terragrunt's 'Error: Can't evaluate expression - The local reference is not evaluated' by breaking the circular local reference. Use when two locals reference each other and neither can be evaluated. Not for genuinely missing locals.
TL;DR: Two of your locals reference each other (a = local.b, b = local.a), so neither can ever be evaluated. The error never says "circular", which is why it's hard to grep for. Compute the shared value once and have both locals read it.
Error: Can't evaluate expression
on terragrunt.hcl line 5, in locals:
5: b = local.a
The local reference 'a' is not evaluated. Either it is not ready yet in the current pass, or
there was an error evaluating it in an earlier stage.Steps
- Run
terragrunt renderto find the first unresolvable local.
Expected: render stops at the failing local.
- Trace its references: does the chain lead back to itself (directly, or through
read_terragrunt_configthat reads the file it started in)?
Expected: you find the loop.
- Break it: compute the shared part once in a third local and have both reference that, or move the shared value into a file both read.
Expected: the reference graph is acyclic.
- Re-run.
Expected: locals evaluate; the error is gone.
When this applies
Can't evaluate expression/is not evaluatedpointing at alocalsblock.- After a rename, where a local now references itself under the new name.
When it doesn't apply
- The same message with NO cycle: "or there was an error evaluating it in an earlier stage" means something the local calls failed (
read_terragrunt_configon a missing file,get_envwith no default). Fix the underlying call. Error: Unsupported attributeonlocal.x: the local doesn't exist at all, different fix.
Tool versions
All Terragrunt 1.x (reproduced on 1.1.3).
Why it happens
Terragrunt evaluates locals in passes, resolving references incrementally. A cycle means no pass can ever resolve either side, and the error reports the symptom ("not evaluated") rather than the cause ("circular").
Edge cases
- Indirect cycles through
read_terragrunt_configare the sneaky ones: file A reads file B which reads file A.render --log-level debugshows the evaluation order. dependencyoutputs are not resolvable insidelocalsat all; a local reaching for them fails the same way without being circular.