---
question: "What's the difference between a unit and a stack?"
description: "A unit is one piece of infrastructure with its own state, marked by a terragrunt.hcl file. A stack is a collection of units managed together, either as a directory tree of units or as a terragrunt.stack.hcl file that generates them."
order: 4
---

## Unit

A [unit](/features/units/) is a single instance of infrastructure that Terragrunt manages: one VPC, one database, one cluster. A directory containing a `terragrunt.hcl` file is a unit, and each unit gets its own state file. Units are the target of a single run, so `terragrunt apply` inside a unit directory applies exactly that unit.

## Stack

A [stack](/features/stacks/) is a collection of units managed together, such as every unit that makes up one environment or one region. Units in a stack can depend on each other, and Terragrunt orders them using the DAG built from their [`dependency` blocks](/reference/hcl/blocks#dependency).

Stacks come in two forms:

- **[Implicit stacks](/features/stacks/implicit/)** are just a directory tree of units. Nothing declares the stack; it is the set of units Terragrunt discovers under the directory you run from.
- **[Explicit stacks](/features/stacks/explicit/)** are declared in a `terragrunt.stack.hcl` file, which generates units into a `.terragrunt-stack` directory from sources you point at. This lets you define a pattern once and instantiate it repeatedly with different [`values`](/reference/hcl/blocks#unit).

A single directory cannot be both. Putting a `terragrunt.hcl` and a `terragrunt.stack.hcl` side by side in the same directory is an error.

## Which commands apply to which

| Command | Operates on |
| --- | --- |
| `terragrunt plan`, `terragrunt apply` | The unit in the current directory |
| `terragrunt run --all <cmd>` | Every unit discovered under the working directory |
| `terragrunt stack generate` | The `terragrunt.stack.hcl` in the current directory |
| `terragrunt stack run <cmd>` | The units generated by that `terragrunt.stack.hcl` |
| `terragrunt stack output` | Outputs of the units in the generated stack |

Both `run --all` and `stack run` generate explicit stacks before they run, so you do not need a separate `stack generate` step. Pass `--no-stack-generate` to skip it.
