Sefism is free for learners. We are here to help you grow, one step at a time.Join for free
Sefism.

Project structure · Data and DevOps

Terraform project structure

Opens with credits

An infrastructure repository for a small app on AWS: reusable modules, one folder per environment with its own remote state, pinned providers, tests and security scans, with plan on every pull request and apply from CI. For students who have finished the Terraform tutorials and want to know how a real team lays out the files. The same layout works unchanged with OpenTofu.

Curated by Tauseef FayyazIntermediate133 files and foldersTerraform 1.16 (also runs on OpenTofu 1.13), AWS provider 6.x, TFLint 0.64 with the AWS ruleset 0.49Checked October 2026
Explore the filesPick any file to see what it is, why it exists and when you add it.

How it grows

Each stage opens the explorer there

  1. 1Day 1What the scaffold and your first hour give you16 files and folders
  2. 2GrowingWhat a real app with features and tests adds+54 files and folders
  3. ProductionWhat running it for real users adds+27 files and foldersOpens with credits
  4. ExpertWhat a team needs to keep it healthy for years+36 files and foldersOpens with credits

How it is organised

  • Reusable code lives in `modules/`; each folder in `environments/` is a root module that calls those modules with its own values and has its own state.
  • One state per environment. A plan in dev can never change prod, and you can see every environment's settings by opening its folder.
  • State lives in a versioned, encrypted S3 bucket with locking. Never in Git, never only on a laptop.
  • Follow the HashiCorp style guide file names: `terraform.tf` for versions, `providers.tf`, `backend.tf`, `main.tf`, `variables.tf`, `outputs.tf`, `locals.tf`.
  • Pin versions in layers: `.terraform-version` pins the CLI, `required_providers` sets the allowed range, and the committed `.terraform.lock.hcl` pins the exact provider build.
  • Reusable modules declare minimum versions only and have no lock file in Git; root modules decide the exact versions.
  • Every change goes through a pull request that shows the plan. Only CI applies, with short-lived OIDC credentials and an approval for prod.
  • Test cheaply first: fmt, validate and TFLint on every save, mocked `terraform test` on every push, scanners and policies on every plan, real apply tests before a module release.
  • No secrets in `.tf` or `.tfvars` files. Let the cloud generate and store them (Secrets Manager, managed passwords) and pass references around.
  • Write code that both Terraform and OpenTofu accept unless you have decided otherwise; use `.tofu` files only for OpenTofu-only features.

At the top of the project

Open one in the explorer for the full story

Learn more on Sefism

Roadmaps, cheat sheets and projects that go with Terraform.

See 7 more
Checked against 21 official sources, October 2026. If something has changed, the docs win.Show sources

Picked from the other libraries by shared topics.

Work with me

Stuck on something specific?

Writing only gets you so far. If you want an answer to your situation rather than the general case, book a session and we will work through it together. Sessions are free for approved Sefism members, and a few slots open each week.

  • 1:1 Mentorship
  • Fresh Graduate Mentorship
  • Career Guidance

Brand deals, promos and partnerships: tauseeffayyaz@gmail.com