How to enable provider caching when using Terragrunt
Last updated: July 14, 2025
When working with Terragrunt in Spacelift, you can enable provider caching to improve performance by preventing repeated downloads of provider binaries. Here's how to set it up correctly:
Prerequisites
Ensure you have:
A configured worker pool with binariesCacheVolume
Access to modify contexts in your Spacelift environment
Setting Up Provider Caching
To enable Terragrunt provider caching, you need to:
Set the environment variable
TERRAGRUNT_PROVIDER_CACHE=1in your context and attach it to your stack.Note: The newer
TG_PROVIDER_CACHEvariable is not supported. UseTERRAGRUNT_PROVIDER_CACHEinstead.For standard Terraform provider caching (non run-all stacks), you can also use the
TF_PLUGIN_CACHE_DIRenvironment variable to specify where provider binaries should be stored.
Important Considerations
Keep in mind these key points:
The
binariesCacheVolumein worker pools only caches core binaries (Terraform, Terragrunt, OpenTofu, kubectl) - it does not cache Terraform providers.Provider binaries need their own dedicated storage space separate from the node's ephemeral storage.
You can verify if caching is working by checking the contents of your cache directory:
ls -lah /mnt/ebs/terragrunt-cache
Troubleshooting
If provider caching isn't working:
Verify the
TERRAGRUNT_PROVIDER_CACHEenvironment variable is set correctly in your contextCheck if providers are being re-downloaded in each run by reviewing the logs
Monitor disk usage with
df -hto ensure you have sufficient storage spaceEnsure your cache directory is properly mounted and accessible
For more information about worker pools and binary caching, see the Spacelift Binaries Cache documentation.