Terraform Minimal Project Structure

Single environment, flat file structure. All resources in root. Perfect for small projects.

#terraform #iac #devops #infrastructure #minimal

Project Directory

infra/
main.tf
Primary resources
Primary resources
variables.tf
Input variables
Input variables
outputs.tf
Output values
Output values
providers.tf
Provider configs
Provider configs
versions.tf
Version constraints
Version constraints
terraform.tfvars
Variable values
Variable values
locals.tf
Local values
Local values
data.tf
Data sources
Data sources
backend.tf
State backend config
State backend config
.terraform.lock.hcl
Provider lock file
Provider lock file

Why This Structure?

Flat structure works well for small infrastructure: one VPC, a few resources, single environment. All .tf files in the root are merged by Terraform, so splitting by concern (variables.tf, outputs.tf) keeps things organized without complexity.

Key Directories

  • main.tf-Resources—EC2, RDS, S3, etc.
  • variables.tf-All input variable definitions
  • outputs.tf-Values to expose after apply
  • providers.tf-AWS, GCP, Azure provider blocks
  • terraform.tfvars-Actual values (gitignored in prod)

Getting Started

  1. mkdir infra && cd infra
  2. Create providers.tf with your cloud provider
  3. Define variables in variables.tf
  4. terraform init
  5. terraform plan
  6. terraform apply

When To Use This

  • Single environment (dev only, or prod only)
  • Small infrastructure (< 20 resources)
  • Learning Terraform basics
  • Quick prototypes and POCs
  • Personal projects

When To Upgrade

  • Need dev/staging/prod environments
  • Resources exceed 50+ items
  • Team members stepping on each other
  • Want reusable infrastructure modules
  • Need to share modules across projects

Naming Conventions

  • Files-Lowercase with underscores: security_groups.tf
  • Resources-snake_case: aws_instance.web_server
  • Variables-snake_case: instance_type, vpc_cidr
  • Outputs-snake_case: instance_public_ip