Introduction
Today we focus on file structure and organising Terraform projects. Initially all resources were placed in a single main.tf file to simplify the learning process. What we are doing now is to improve the project structure by splitting resources and configurations into multiple files for better readability, collaboration and maintainablity.
The root directory of a Terraform project is called the root module.
Terraform File Loading
There is no strict mandatory naming convention for Terraform files.recommendations come from HashiCorp best practices but are flexible.
How Terraform loads files;
Terraform loads all .tf files in the current directory
Files are loaded in lexicographical order (alphabetical)
All .tf files are merged into a single configuration
Recommended File Structure and Best Practices
project-root/ βββ backend.tf # Backend configuration βββ provider.tf # Provider configurations βββ variables.tf # Input variable definitions βββ locals.tf # Local value definitions βββ main.tfβ¦