Skip to content

Running Many Units at Once

terragrunt run --all apply walks every unit under the current directory, applies them in the order the dependency graph from the previous lesson requires, and --filter narrows that walk to a subset of the tree without changing how the ordering is computed.

run —all: operating on every unit in the tree

Section titled “run —all: operating on every unit in the tree”

Once a directory contains more than one unit, running terragrunt plan or terragrunt apply inside each one by hand does not scale. run --all fans a single command out across every unit found under the current directory:

Terminal window
terragrunt run --all plan
terragrunt run --all apply

Be careful with search results and older tutorials here — this is a module where advice goes stale fast. terragrunt run-all plan and terragrunt run-all apply are the old syntax and are now deprecated in favor of run --all. Older still, terragrunt plan-all and terragrunt apply-all are not just deprecated, they have been removed entirely and will simply fail on a current Terragrunt install. If a guide you are reading tells you to run apply-all, treat that as a sign the rest of the guide may be out of date too.

Running every unit in an entire repository is not always what you want — sometimes you only touched one subscription’s units and want to plan just those. The --filter flag scopes a run --all to a subset of the tree using a glob pattern:

Terminal window
terragrunt run --all --filter './subscription-a/**' -- plan

--filter replaced the older --queue-include-dir and --queue-exclude-dir flags, which worked similarly but as two separate flags for including versus excluding paths. The -- before plan separates Terragrunt’s own flags from the command being run across the units, which matters once a run --all invocation starts combining flags like --filter with the underlying Terraform command.

For CI pipelines, where nothing should ever pause waiting for a human to confirm a prompt, add --non-interactive:

Terminal window
terragrunt run --all --non-interactive -- apply

--non-interactive replaced the older --terragrunt-non-interactive flag — another naming pattern to watch for in older material, since several flags used to carry a terragrunt- prefix that current Terragrunt has dropped.

before_hook and after_hook: hooking into a unit run

Section titled “before_hook and after_hook: hooking into a unit run”

A run --all tells Terragrunt which units to touch and in what order, but sometimes a unit needs a side effect wrapped around its own plan or apply — a validation script beforehand, or a notification afterward. before_hook and after_hook blocks, declared inside a unit’s terraform block, run an arbitrary shell command at exactly those points:

vm/terragrunt.hcl
terraform {
before_hook "validate_inputs" {
commands = ["plan", "apply"]
execute = ["./scripts/validate-inputs.sh"]
}
after_hook "notify_slack" {
commands = ["apply"]
execute = ["./scripts/notify-slack.sh", "vm apply finished"]
run_on_error = true
}
}

commands lists which Terragrunt commands trigger the hook, execute is the actual command Terragrunt runs, and run_on_error = true on the after_hook above means the Slack notification fires even if the apply itself failed — useful when you want to hear about failures, not just successes. Because these hooks live inside the unit’s own terragrunt.hcl, they run whether that unit is applied on its own or as part of a larger run --all apply sweeping through many units.

flowchart LR
  cmd["terragrunt run --all apply"]
  cmd --> vnet["vnet unit"]
  vnet --> vm["vm unit (depends on vnet)"]
  vnet --> database["database unit (depends on vnet)"]
  vm --> hook["after_hook notify_slack"]
run --all apply fanning out in dependency order, with a hook firing after one unit completes
What is the current command for running plan across every unit under a directory
What happened to plan-all and apply-all, and what happened to run-all
What is a before_hook or after_hook used for
What determines the order units are processed in during a run --all apply