Terraform Module Standards - Are outputs required to be placed in outputs.tf?

I had some questions with regards to the Terraform module standards as referenced here: Standard Module Structure - Terraform by HashiCorp

I am working on getting some TF modules ready to be published to a TF registry and we have a convention of keeping the outputs close to the module/resource definitions so developers don’t need to switch files. The documentation states that main.tf , variables.tf , outputs.tf, are recommended and not required. But it also states the following:

variables.tf and outputs.tf should contain the declarations for variables and outputs, respectively.

The language suggests that the variables and outputs “should” be placed in these files, but not 100% required. Is this accurate and will the registry reject if the outputs are located outside of outputs.tf?

Hi @mveitas,

As you know, Terraform itself doesn’t care about filenames and just treats all .tf files as equal within a module, apart from the special case of “Override Files”, and the module registry follows that same convention.

Internally it processes modules using terraform-config-inspect, which is a library maintained by the Terraform team that implements a subset of Terraform’s own module loading logic in a way that’s backward and forward compatible with different versions of the Terraform language, and that library preserves the idea that the filenames are decided by the author, not by Terraform itself.

The module registry does have some conventions of its own about the directory structure of your repository – the placement of potentially-multiple module directories – but its handling of the contents of those directories is consistent with Terraform and the conventions documented there are recommendations, rather than requirements.