Key Terraform Rule
Terraform loads and merges ALL
.tffiles in a directory automatically.
There is:
-
❌ no “main file”
-
❌ no execution order by filename
-
✅ one configuration per directory
So:
applies everything in that folder.
✅ How You SHOULD structure your files
๐ Recommended folder structure
Terraform reads them all together.
LAB- BREAK YOUR MAIN.TF INTO DIFFERENT COMPONENTSprovider.tf
data.tf
instance.tf
outputs.tf
▶️ Running Terraform
From the directory:
Terraform automatically:
-
loads all
.tffiles -
builds the dependency graph
-
applies in the correct order
❌ Common misconception
“Terraform executes files top to bottom”
Wrong.
Terraform:
-
builds a dependency graph
-
executes based on references
-
ignores file order and filenames
๐ง KEY TAKEAWYS
Terraform directory = one application
.tffiles = chapters in the same book
You don’t run chapters — you run the book.
๐งช Advanced (Optional): Lab separation strategies
Option A — New folder per lab (recommended for beginners)
Option B — Same folder, comment/uncomment (not ideal)
Option C — Use variables / count (advanced)
⚠️ One important rule
Terraform only reads files in the current directory.
Subfolders are ignored unless you use modules (advanced topic).
✅
-
You don’t “apply a file”
-
You apply a directory
-
Terraform merges all
.tffiles automatically -
File naming is for human readability only
๐ง One-sentence takeaway for students
Terraform applies directories, not files.