Junior — Middle
How would you organize the file structure for Terraform in your project?
sobes.tech AI
Answer from AI
The organization of Terraform's file structure in a project depends on the scale and requirements, but generally follows these principles:
-
Environment separation — separate folders for dev, staging, prod to isolate configurations and states.
-
Modules — grouping reusable components into
modules/folders to avoid code duplication. -
Main configurations — placing
main.tf,variables.tf,outputs.tffiles in the root or environment folders.
Example structure:
terraform/
├── modules/
│ ├── network/
│ ├── compute/
│ └── database/
├── envs/
│ ├── dev/
│ │ ├── main.tf
│ │ ├── variables.tf
│ │ └── backend.tf
│ ├── staging/
│ └── prod/
└── README.md
This approach facilitates maintenance, scaling, and collaboration on infrastructure.