Terragrunt for Beginners

Terragrunt Good to Know Concepts Ideas

Terragrunt Cache

Terragrunt creates a hidden cache directory (.terragrunt-cache) as a local “scratchpad” to speed up your Terraform workflows. This cache helps with:

  • Downloading remote Terraform configurations, modules, and providers
  • Executing Terraform commands in an isolated workspace
  • Ensuring that you can delete and recreate the cache at any time without impacting live infrastructure

Note

The cache size grows as your project’s number of modules and providers increases. Plan for disk usage accordingly.

How Terragrunt Uses the Cache

When you run a Terragrunt command, it:

  1. Fetches remote Terraform configurations and modules into .terragrunt-cache.
  2. Initializes a temporary working directory for Terraform to apply changes.
  3. Cleans up after execution, leaving .terragrunt-cache in place for future runs.

The image is a diagram explaining the Terragrunt cache process, showing steps like downloading Terraform config remotely, running Terraform commands, and indicating that the cache can be safely deleted and recreated.

Pruning Cache Directories

Over time, you may accumulate many .terragrunt-cache folders across your repo. To reclaim disk space, run these commands from your project root:

ActionCommand
List all cache directoriesbash<br>find . -type d -name ".terragrunt-cache"
Delete all cache directoriesbash<br>find . -type d -name ".terragrunt-cache" -prune -exec rm -rf {} \;

Warning

The delete command uses rm -rf. Double-check your working directory before running irreversible removal commands.

Centralizing Cache Storage

You can direct all .terragrunt-cache directories to a single folder by setting the TERRAGRUNT_DOWNLOAD_DIR environment variable. This makes it easier to manage and monitor cache usage.

The image instructs to set the environment variable "TERRAGRUNT_DOWNLOAD" for Terragrunt Cache.

Configure Your Shell

Add the following to your shell configuration file (~/.bashrc, ~/.zshrc, etc.):

export TERRAGRUNT_DOWNLOAD_DIR="/path/to/central/cache"

Then, reload your shell:

source ~/.bashrc  # or source ~/.zshrc

Note

From now on, Terragrunt will store every .terragrunt-cache in "/path/to/central/cache". You can periodically clean this directory to reclaim space.

Watch Video

Watch video content

Previous
TerraformOpenTofu and Terragrunt Compatibility Chart