Bottom Line: It is 100% safe to delete .terraform folders. Running rm -rf .terraform will NOT delete your infrastructure code (.tf files) or your Terraform state (.tfstate).
What is the .terraform Folder?
Located inside Infrastructure-as-Code projects using HashiCorp Terraform or OpenTofu, the .terraform folder is created when you run terraform init.
Terraform downloads heavy cloud provider binary plugins (like hashicorp/aws, hashicorp/azurerm, or hashicorp/google) into .terraform/providers. Each cloud provider plugin binary is 150 MB to 400 MB.
If you work on dozens of DevOps repositories, duplicate provider binaries in every project directory easily waste 10 GB to 30 GB+.
Can You Delete .terraform?
✅ Yes, it is completely safe to delete.
- Zero code risk: Your
.tfHCL files and remote.tfstatefiles remain untouched. - Auto-downloaded: Running
terraform initin the project folder will re-fetch the necessary provider plugins.
How to Safely Clean Up Terraform Cache
Method 1: Delete Local Project .terraform Folders
# macOS / Linux
find . -type d -name ".terraform" -exec rm -rf {} +
# Windows (PowerShell)
Get-ChildItem -Include .terraform -Recurse -Force | Remove-Item -Recurse -Force
Method 2: Enable Global Plugin Cache (Prevents Future Waste)
Add this line to your ~/.terraformrc (or %APPDATA%\terraform.rc on Windows) to share one central plugin binary cache across all project repos:
plugin_cache_dir = "$HOME/.terraform.d/plugin-cache"
Related Guides
- Learn about deleting Helm cache.
- How to clean up Podman storage.
- Check if you can clean git folders.
Discussion
Loading authentication...