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:
- Fetches remote Terraform configurations and modules into
.terragrunt-cache
. - Initializes a temporary working directory for Terraform to apply changes.
- Cleans up after execution, leaving
.terragrunt-cache
in place for future runs.
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:
Action | Command |
---|---|
List all cache directories | bash<br>find . -type d -name ".terragrunt-cache" |
Delete all cache directories | bash<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.
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.
Links and References
Watch Video
Watch video content