Can I Delete the .terraform Folder? Yes, It's Safe
**/.terraformYes, you can delete the .terraform folder. It only holds downloaded provider plugins and modules for that one project, and running terraform init rebuilds all of it. Your configuration files, your state, and your lock file live outside it and are not touched. The only cost is a re-download the next time you work in that project.
What it is
Terraform creates a hidden .terraform folder inside every project directory the first time you run terraform init. It is a per-project cache. The providers subfolder holds the actual plugin binaries Terraform needs to talk to your cloud, and these are big native executables: in recent versions the AWS, Google, and Azure providers each unpack to hundreds of megabytes. The modules subfolder holds a copy of every remote module your configuration references. There is also a small amount of metadata, including a file that records which backend the project was initialized against.
It grows because every project gets its own private copy of everything. Terraform does not share providers between directories unless you explicitly configure a plugin cache, so ten repos that all use the AWS provider means ten separate copies of the same binary. One .terraform folder is often a few hundred megabytes, and if you touch a lot of infrastructure repos the combined total across your Mac can reach several gigabytes.
Is it safe to delete?
This folder is in the safe tier. Deleting it removes only downloaded artifacts, and terraform init fetches them all again on demand. Nothing about your real infrastructure changes. Terraform state, the record of what actually exists in your cloud account, lives in terraform.tfstate in the project root if you use the local backend, or in a remote backend like S3 or HCP Terraform. It is never stored inside the provider cache. Projects with a remote backend do keep a small file named terraform.tfstate inside .terraform, but despite the name it only records backend settings, and init recreates it.
What you give up is time and bandwidth. The next terraform plan or apply in that project will refuse to run until you re-init, and pulling a large provider on a slow connection can take a few minutes. The one thing to be careful about is aim: delete the .terraform folder itself, not the terraform.tfstate file or the .terraform.lock.hcl file sitting next to it in the project root. Those are yours. Diskmack finds .terraform folders across all your projects automatically and cleans them the safe way.
How to check its size
In Finder: In Finder, choose Go > Go to Folder and enter your project path, for example ~/projects/my-infra. Press Command-Shift-Period if hidden files are not visible, then select the .terraform folder and press Command-I to see its size.
In Terminal:
du -sh ~/projects/my-infra/.terraformReplace ~/projects/my-infra with your project's real path; the ~ expands to your home folder. If the path contains spaces, quote that part, like du -sh ~/"My Projects/my-infra"/.terraform. To list every copy under your home folder with sizes, run find ~ -type d -name .terraform -prune -exec du -sh {} + 2>/dev/null; the last part hides permission warnings from folders macOS protects.
How to clean it
- Make sure no terraform plan or apply is running in that project.
- Open the project folder in Finder and press Command-Shift-Period to show hidden files.
- Select the .terraform folder (the folder, not the .terraform.lock.hcl file) and drag it to the Trash.
- Leave terraform.tfstate and .terraform.lock.hcl in the project root exactly where they are.
- Empty the Trash, then run terraform init the next time you work in that project to re-download providers and modules.
Do not delete terraform.tfstate or .terraform.lock.hcl from the project root. The state file records your real infrastructure, and the lock file pins provider versions and belongs in version control. Both are small anyway.
Will it come back?
Yes, and quickly. The next terraform init rebuilds the folder at roughly its old size, because it re-downloads the same providers and modules your configuration requires. If the regrowth across many projects bothers you, set the TF_PLUGIN_CACHE_DIR environment variable to a single shared directory (create that directory yourself first; Terraform silently ignores the setting if it doesn't exist). Terraform will then keep one copy of each provider there and link to it from every project, which cuts the duplication down to almost nothing.
Common questions
Will deleting .terraform destroy my infrastructure or my state?
No. Your infrastructure lives in your cloud account, and the state that describes it lives in terraform.tfstate in the project root or in a remote backend such as S3 or HCP Terraform. The .terraform folder is only a cache of downloaded plugins and modules.
Should I delete .terraform.lock.hcl too?
No. The lock file pins the exact provider versions your project has been tested with, and it is meant to be committed to version control. It is only a few kilobytes, so deleting it saves nothing and can cause version drift.
How do I find every .terraform folder on my Mac?
Run find ~ -type d -name .terraform -prune -exec du -sh {} + 2>/dev/null in Terminal (the 2>/dev/null part hides permission warnings). It lists each copy with its size so you can decide which projects are worth cleaning.
Why is my .terraform folder so large?
Provider plugins are full native binaries. The big cloud providers are each hundreds of megabytes unpacked, and every project keeps its own copy. A shared cache via TF_PLUGIN_CACHE_DIR is the long-term fix.
Related folders
- Is It Safe to Delete the Go Module Cache (~/go/pkg/mod) on a Mac?
- Clearing the Cargo Cache on Mac: Is ~/.cargo/registry Safe to Delete?
- Rust target Folder Is Huge: Is It Safe to Delete?
- Can I Delete the .gradle Folder on My Mac? Yes, Here's How
- Can I Delete the .m2 Folder on My Mac? (Maven Repository Cache)
- Docker Desktop Taking Up Space on Mac: What's Safe to Delete