Terraform module disk usage

Hi All,

How do we prevent terraform from downloading the same repo data multiple times to the local module folder?

module “test1” {
source = “git@test.com:aravind/terraform.git//test1”

module “test2” {
source = “git@test.com:aravind/terraform.git//test2”

The above configuration is downloading the entire repo two times instead of the module sub directory. This causes a lot of disk space usage when you have multiple modules using same source repo

Aravind M D

Hi @ambadiaravind,

Terraform must create a separate directory for each call because sometimes modules modify their own directories during execution, such as when using resources like local_file from the hashicorp/local provider.

There is no way to avoid those copies. Instead, you could try one of the following:

  • Separate your modules into a number of smaller repositories, so that each module package is smaller.
  • Place the module that contains these module blocks in the same repository as the modules it is calling and then refer to those modules using relative local paths instead, like source = "../test2". Terraform treats local paths as special and will just use the directory already on your local disk, instead of downloading anything new.
1 Like