Where Does Terraform Store Plugins and State Data?
Terraform splits state between per-project .terraform folders and a home-directory .terraform.d. Plugin, config and cache paths for every OS.
Last updated
Terraform keeps two very different kinds of files in two different places. Per-project data, providers, modules and backend state, goes in a .terraform folder inside each working directory. Per-user data, manually installed providers, the plugin cache and the CLI config, lives in .terraform.d in your home directory plus a single rc file.
The naming is the trap: .terraform in the project versus .terraform.d in home, one letter apart. The project folder is disposable cache that init rebuilds. The home folder holds your plugin mirror and credentials setup, so treat it as configuration. TF_DATA_DIR and TF_PLUGIN_CACHE_DIR move either side when defaults do not fit.
Where Terraform stores this, by platform
%APPDATA%\terraform.d
CLI config is %APPDATA%\terraform.rc; user plugins live in %APPDATA%\terraform.d\plugins. Per-project data sits in .terraform inside each working directory. Set TF_CLI_CONFIG_FILE to relocate the rc file and TF_DATA_DIR to move project data elsewhere.
~/.terraform.d
CLI config is ~/.terraformrc directly in home. User plugins live in ~/.terraform.d/plugins with OS and architecture subfolders. Set TF_PLUGIN_CACHE_DIR to enable the shared provider cache; you must create the cache directory yourself first.
~/.terraform.d
Same layout as macOS: ~/.terraformrc for config, ~/.terraform.d/plugins for providers, ~/.terraform.d/plugin-cache when caching is enabled. Terraform ignores XDG base directories here and always uses the home dotfolder, which surprises tidiness minded Linux users.
Frequently asked questions
how do i speed up terraform init with a plugin cache
Add plugin_cache_dir to your CLI config pointing at $HOME/.terraform.d/plugin-cache, or export TF_PLUGIN_CACHE_DIR for the session. Create the directory first; Terraform will not create it. Later inits then reuse downloaded providers instead of fetching them per project.
is it safe to delete the terraform folder
Yes, with one condition: run terraform init again afterward. The folder holds downloaded providers and modules that init recreates from your lock file. Never delete the .tfstate files or the lock file alongside it; those are your actual infrastructure record, not cache.
how do i move terraform data out of my project folder
Set TF_DATA_DIR to another path. Terraform then keeps its per-directory data there instead of .terraform. This matters for automation where the working directory is read-only or shared. The variable changes only the data location, not where your .tf files live.
Notice an outdated path? Let us know.