0
0
Terraformcloud~10 mins

File naming conventions (.tf files) in Terraform - Step-by-Step Execution

Choose your learning style9 modes available
Process Flow - File naming conventions (.tf files)
Start Terraform Project
Create .tf files
Name files by purpose
Terraform loads all .tf files
Apply configuration
End
Terraform reads all .tf files in a folder. Naming files by purpose helps organize and understand the project.
Execution Sample
Terraform
main.tf
variables.tf
outputs.tf
network.tf
security.tf
Example of common Terraform file names showing how to separate configuration by purpose.
Process Table
StepActionFile NamePurposeEffect
1Create main configuration filemain.tfDefines main resourcesTerraform loads main resources
2Create variables filevariables.tfDefines input variablesTerraform knows inputs to expect
3Create outputs fileoutputs.tfDefines outputsTerraform knows what to show after apply
4Create network config filenetwork.tfDefines network resourcesNetwork setup separated for clarity
5Create security config filesecurity.tfDefines security groups and rulesSecurity setup separated for clarity
6Terraform loads all .tf filesAll .tf filesCombined configurationTerraform merges all configs before apply
7Apply terraformN/AExecute planInfrastructure created as defined
8EndN/ACompleteProject deployed successfully
💡 All .tf files loaded and merged; terraform apply completes deployment
Status Tracker
FileCreatedPurpose DefinedLoaded by Terraform
main.tfYesYesYes
variables.tfYesYesYes
outputs.tfYesYesYes
network.tfYesYesYes
security.tfYesYesYes
Key Moments - 3 Insights
Why do we split Terraform configuration into multiple .tf files?
Splitting files by purpose (see execution_table steps 1-5) helps organize code, making it easier to read and maintain.
Does Terraform care about the order or names of .tf files?
No, Terraform loads all .tf files in the folder together regardless of name or order (see execution_table step 6).
Can we name .tf files anything we want?
Yes, but using descriptive names like variables.tf or network.tf helps others understand the project quickly (see execution_table steps 2 and 4).
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table, which file defines input variables?
Avariables.tf
Bmain.tf
Coutputs.tf
Dnetwork.tf
💡 Hint
Check the Purpose column in execution_table row 2
At which step does Terraform load all .tf files together?
AStep 3
BStep 5
CStep 6
DStep 7
💡 Hint
Look for 'Terraform loads all .tf files' in execution_table
If we add a file named database.tf, what will happen during terraform apply?
ATerraform ignores database.tf
BTerraform loads database.tf and merges its config
CTerraform errors because of unknown file
DTerraform only loads main.tf and variables.tf
💡 Hint
Refer to execution_table step 6 about loading all .tf files
Concept Snapshot
Terraform reads all .tf files in a folder together.
Name files by purpose: main.tf, variables.tf, outputs.tf, etc.
File order and names do not affect loading.
Organizing files improves readability and maintenance.
Add new .tf files anytime; Terraform merges all configs.
Full Transcript
Terraform projects use multiple .tf files to organize infrastructure code. Each file has a purpose, like main.tf for main resources, variables.tf for inputs, and outputs.tf for outputs. Terraform loads all .tf files in the folder together, regardless of their names or order. This means you can split your configuration into logical parts for clarity. When you run terraform apply, it merges all these files and applies the combined configuration. Naming files clearly helps you and others understand the project structure easily.