How to set a common .terraform folder instead of individual ones?

I have 100 clients where I perform terraform actions.

These 100 clients are in 100 sub-folders where each sub-folder has its .tf and plan files etc.

Thing is, each of these subfolders have its own .terraform folder which contains the providers folder which is minimum 300MB each and a result of which my terraform client folder is over 30GB.

Is there no way to centralize the .terraform or providers folder ?

This is on a Linux machine but would like to know the solution for Windows 11 as well.

Follow the documentation at CLI Configuration | Terraform | HashiCorp Developer to configure a central plugin cache to be reused for multiple Terraform root directories.


Thanks for the solution.

Is there some terraform.ini file where we can make this setting ?

EDIT : CLI Configuration | Terraform | HashiCorp Developer

So if I place in ~/.terraformrc :

plugin_cache_dir   = "$HOME/.terraform.d/plugin-cache"

all the terraform-provider-* files would be in ~/terraform.d/plugin-cache ?

yes it would, in directories like ~/.terraform.d/plugin-cache/

1 Like