Skip to content

Implicit Stacks

The simplest way to create a stack is to organize your units in a directory structure in your repository. When you have multiple units in a directory, Terragrunt automatically treats that directory as a stack for the purposes of commands like terragrunt run --all apply.

Let’s say your infrastructure is defined across multiple OpenTofu/Terraform root modules:

  • Directoryroot
    • Directorybackend-app
      • main.tf
    • Directoryfrontend-app
      • main.tf
    • Directorymysql
      • main.tf
    • Directoryvalkey
      • main.tf
    • Directoryvpc
      • main.tf

To convert these to Terragrunt units, simply add a terragrunt.hcl file to each directory:

  • Directoryroot
    • Directorybackend-app
      • main.tf
      • terragrunt.hcl
    • Directoryfrontend-app
      • main.tf
      • terragrunt.hcl
    • Directorymysql
      • main.tf
      • terragrunt.hcl
    • Directoryvalkey
      • main.tf
      • terragrunt.hcl
    • Directoryvpc
      • main.tf
      • terragrunt.hcl

Now you have an implicit stack! The root directory contains all your units and can be managed as a single stack.

Use the --all flag to run an OpenTofu/Terraform command on all units in the implicit stack in the current working directory:

Terminal window
# Deploy all units discovered in the current working directory
terragrunt run --all apply
# Plan changes across all units discovered in the current working directory
terragrunt run --all plan
# Destroy all units discovered in the current working directory
terragrunt run --all destroy
# View outputs from all units discovered in the current working directory
terragrunt run --all output

You can also use the --graph flag to run an OpenTofu/Terraform command on all units in the DAG of the unit in the current working directory.

Terminal window
# Run an OpenTofu/Terraform command on all units in the DAG of the unit in the current working directory
terragrunt run --graph apply
  • Simple: Just organize units in directory trees.
  • Familiar: Organized following best practices for OpenTofu/Terraform repository structures.
  • Flexible: Easy to add/remove units by creating/deleting directories.
  • Version Control Friendly: Each unit is a separate directory with its own history.
  • Backwards Compatible: This has been the default way to work with Terragrunt for over eight years, and the majority of existing Terragrunt configurations use this approach.
  • Manual Management: Each unit must be manually created and configured.
  • No Reusability: Patterns can’t be easily shared across environments.
  • Repetitive: Similar configurations must be duplicated or referenced from includes.