skip to content

A Terragrunt plan for `live/dev/us-east-1/app` shows `vpc-mock` as its VPC ID because `../vpc` was never applied. What is happening, and how do you stop that value reaching a real apply?

level: seniorimportance: should knowfreq 37%

answer

  1. no outputs to read yet
  2. a substitute map on the block
  3. unset means every command
  4. a saved plan keeps the fake

basics

~20 s

The dependency block found no outputs in the unapplied vpc unit, so Terragrunt substituted mock_outputs. With no allow-list those mocks work for every command, so set mock_outputs_allowed_terraform_commands and never apply a saved plan built on mocks.

solid answer

~40 s

`dependency "vpc"` reads outputs from `../vpc`, and since that unit has none, Terragrunt substitutes the block's `mock_outputs`, so `plan` works on a new stack. The trap is scope. Without `mock_outputs_allowed_terraform_commands`, mocks are allowed for every command, so a single-unit `terragrunt apply` can send `vpc-mock` into a real apply. I would set the allow-list to `validate` and `plan`, which makes `apply` fail instead. That does not cover saved plans: `run --all --out-dir` on a greenfield stack stores mock values in the plan files, so those must be discarded and re-planned once the dependency exists. An ordinary `run --all apply` is fine, because it applies `vpc` first and reads real outputs.

go deeper

for a junior

Recall that a dependency block reads another unit's outputs and that mock_outputs stands in when that unit has not been applied, so plan can run on a new stack.

for a middle

Explain the allow-list and what an unset one means, and the difference between mock_outputs, skip_outputs and the shallow merge strategy.

for a senior

Trace how a fake value reaches a real apply: unset allow-list on a single-unit apply, saved plans made on a greenfield stack, and a merge strategy left unrestricted. Then give the guardrails.

for a principal

Set a repository-wide rule rather than trusting each author, such as an allow-list on every dependency's mocks and no saved plans across a first apply. Weigh a greenfield plan that previews invented values against one that fails.

## What a `dependency` block does A Terragrunt **unit** is a directory with a `terragrunt.hcl` and its own state. A `dependency` block lets one unit read another's outputs: ```hcl # live/dev/us-east-1/app/terragrunt.hcl dependency "vpc" { config_path = "../vpc" mock_outputs = { vpc_id = "vpc-mock" } mock_outputs_allowed_terraform_commands = ["validate", "plan"] } inputs = { vpc_id = dependency.vpc.outputs.vpc_id } ``` It does two things. It adds an edge to the run graph, so `run --all` orders `vpc` first. And it exposes the target's outputs as `dependency.vpc.outputs`. Since v1.2.0 Terragrunt reads them directly from state by default where the backend allows it (S3, GCS and `azurerm`), and through `terraform output` otherwise. The contrast with a `terraform_remote_state` data source is that the handoff lives in Terragrunt's config and arrives as an ordinary input variable. ## Why mocks exist Outputs cannot be read from a unit that has not been applied, so without help `terragrunt plan` on a brand-new stack stops with an error. `mock_outputs` is a map that Terragrunt substitutes in that case. A `vpc-mock` in this plan therefore means Terragrunt found no outputs at `../vpc`. It also logs a warning that the dependency has no outputs and it is returning mocks, which is worth searching a pipeline's log for. The same path fires for a target that simply declares no outputs, because Terragrunt cannot tell that from one never applied. ## When each setting uses the mock | Situation | Result | |---|---| | Real outputs exist | Real values; mocks ignored by default | | No outputs, mocks set, no allow-list | Mocks, for **any** command, `apply` included | | No outputs, command on the allow-list | Mocks | | No outputs, command not on the allow-list | Error | | `skip_outputs = true` with mocks | Mocks where allowed, without loading real outputs | | `mock_outputs_merge_strategy_with_state = "shallow"` | Real outputs, with mocks only for missing keys | ## How a fake value reaches a real apply 1. **No allow-list.** `mock_outputs_allowed_terraform_commands` left unset allows every command. A single-unit `terragrunt apply` on `app`, before `vpc` exists, sends `vpc-mock` into a real apply. It may fail at the provider, or, for a value nothing checks, it may succeed and record a wrong setting. 2. **A saved plan.** `run --all --out-dir /tmp/tfplan -- plan` on a new stack bakes mocks into each plan file, and applying from that directory later applies them. The docs warn about this and say there is no first-class feature to solve it, so an allow-list that omits `apply` does not help in this flow: the plan has already captured the value. 3. **`skip_outputs` left on.** It means "use mocks all the time if they are set". The reference recommends against combining it with `mock_outputs`. `--no-dependency-outputs` has the same effect for a whole run, so keep it to commands that do not need real outputs. 4. **A merge strategy on a live unit.** With `shallow`, a new output that `vpc` has not yet published is filled from the mock while the others are real. That helps `plan` during a roll-out, and with no allow-list it also applies to `apply`. An ordinary `run --all apply` is safer than these. Terragrunt applies `vpc` first and reads real outputs right before applying `app`. If `vpc` fails, `app` does not run. ## How to run this safely - **Always set the allow-list**, commonly `["validate", "plan"]`, or only `["validate"]` if you would rather have a greenfield `plan` fail than show invented values. It is checked against the command you ran. - **Treat a greenfield plan as a preview.** It proves the unit's shape, not what will be created. - **Do not keep saved plans across a first apply.** Apply the graph in order, or re-plan each unit once its dependency is real. - **Match the output's shape.** `subnet_ids` needs a list, and a module's `validation` block can reject a value such as `vpc-mock`, so choose mocks that pass the module's own checks. - **Read the real input when in doubt.** `--inputs-debug` writes the resolved input values to a `terragrunt-debug.tfvars.json` file beside the unit's `terragrunt.hcl`. `terragrunt render` also shows what a unit resolved to, but render commands can use mocks regardless of the allow-list, so its output alone does not prove a value is real. - **Do not read an access error as a missing value.** Mocks cover a missing state object or empty outputs. A failure to read state for another reason stops the run, which is what you want.

  • The `vpc` unit is live, but you just added a new output it has not published yet. Why does the `app` plan fail, and what helps?
    Real outputs exist, so with the default `no_merge` strategy mocks are ignored, and reading the missing key fails. `mock_outputs_merge_strategy_with_state = "shallow"` fills only missing keys from the mock. Keep an allow-list on it, because the merge also honours that list and would otherwise cover `apply`.
  • Why is `skip_outputs = true` a poor companion for `mock_outputs` on a normal unit?
    `mock_outputs` means use mocks only if real outputs are unavailable, while `skip_outputs` means use them all the time if they are set. A unit with both never sees real values. It suits narrow cases such as CI validation with backend initialisation disabled, not everyday configuration.
  • Your CI role can plan `app` but gets an access error reading `../vpc`. Why would a dependency need that?
    Terragrunt reads the target's outputs from its state, so the identity running `app` also needs read access to that state. Mocks do not paper over this: the fallback covers a missing state object or empty outputs, and any other read failure stops the run. Grant the role read access to that state.

A mock output is a placeholder name on a seating chart: good enough to check the chart fits the room, useless once guests arrive. The allow-list says which rehearsals may use placeholders, and a saved plan is a chart already printed with them on it.

  • mock_outputs are only ever used during plan and validate, never during apply.
  • With mocks set, Terragrunt always uses them instead of real outputs on a live unit.
  • A green plan on mock outputs proves what the apply will create.
  • Restricting mocks to validate and plan makes applying a saved plan safe.
  • skip_outputs with mock_outputs still reads real outputs when they exist.
  • An ordinary run --all apply will use mocks for units still waiting on a dependency.