Free — no signup required

Mocking for the First Run

2 min read

The "Chicken and Egg" Plan

There is a subtle problem that appears the moment you try to use dependencies in a brand-new environment. To run terraform plan on the App stack, Terraform needs all input variables filled in. It tries to read the VPC outputs from remote state. But the VPC hasn't been created yet — its state file is empty. The plan fails before you can even see what you are about to build.

This is the classic chicken-and-egg problem: you want to plan before applying, but planning requires outputs that only exist after applying.

Solution: mock_outputs

Terragrunt allows you to provide fake placeholder values that are used only when the real dependency state is unavailable. The mocks are never used during an actual apply — Terragrunt reads the real outputs at that point. A companion setting acts as the safety valve here: it restricts which commands are allowed to fall back to mock values at all. Listing only validate and plan there ensures that mocks can never accidentally be used during an apply. Omit that restriction, and mocks get used for any command where the real state is unavailable — including apply — which can silently deploy infrastructure with wrong values.

A common pattern in large organizations is to commit a mock_outputs_merge_strategy_with_state setting of "shallow", which merges mock values with any real state that partially exists. This handles the case where a dependency stack was partially applied and has some outputs but not all — a scenario that occurs during incremental rollouts of new output variables.

This is one of 18 chapters

Every chapter is free — Kubernetes, Terraform, SRE, distributed systems, and more — with fast daily review built in.

Sign up free