Terraform init doesn't create modules hash folder in .terraform

Hi guys! Terraform init does not create a hash modules folder in .terraform/modules after upgrading TF version from 0.11.15 to TF 0.12.31

Terraform init with version 0.11.15
Screenshot 2022-09-22 at 03.19.43

Terraform init with version 0.12.31
Screenshot 2022-09-22 at 03.19.55

That’s correct.

Terraform makes no guarantee to users about the layout of this folder, and can and has changed it from version to version.

In particular, Terraform v0.12 totally changed the treatment of that directory.

Terraform v0.11 used a hash of a few different strings related to the module, creating something opaque to a user.

Terraform v0.12 has two different approaches depending on the situation:

  • If the source refers to an external module package, Terraform downloads that package into a subdirectory named after the module call path, using the names declared in the module blocks.
  • If the source refers to a local path inside the same module package, Terraform doesn’t create a subdirectory at all and instead just uses the existing directory directly from the calling module’s module package.

Both of these behaviors had the same motivation: Terraform v0.12 introduced useful error messages for the first time and those messages include source file paths. We wanted those paths to look meaningful even if they were in nested modules, and so the opaque checksums were no longer appropriate.

I expect your module call is to a local source directory and so Terraform v0.12 need not create any subdirectory for it. Terraform v0.11 was redundantly copying a directory already on your disk into a subdirectory of modules, even though that wasn’t strictly necessary.

As @maxb says though, this is an implementation detail. I’m describing the current behavior in case you are curious about it, but you should not build tools or processes that rely on it because it is subject to change again in any future version of Terraform.