Language

Terraform files are written in HashiCorp Configuration Language (HCL).

Terraform lock file

It’s a best practice to keep the .terraform.lock.hcl file in version control. HashiCorp’s documentation explicitly suggests it but some people (myself included) don’t do it.

The reasoning behind it is that you have the same versions being shared with the team and with the CI pipelines, therefore enforcing consistency, as well as making the provider upgrades visible as a diff in PRs.

Terraform’s file structure

In Terraform, modules are organized by directories, in which the file structure doesn’t really interfere with the outcome: all files are “combined” into a single configuration which constitutes the module, therefore the way you structure those files only matters for whoever is reading it. The bare minimum recommended structure is having main.tf for all the resources, and both variables.tf and outputs.tf for their respective values.

NOTE

Having a README.md is also recommended if the module would be shared.

On the other hand, if main.tf grows too much, it is recommended, for readability only, to split resources into dedicated files. For example, you could have one called dns.tf for resources related to DNS configuration, and so on.