Skip to content
RED SAGSkills
mediumDevOps Engineer interview question

How do you structure Terraform code for multiple environments like dev, staging and production?

What the interviewer wants to hear

  • Reusable, versioned modules
  • Separate state per environment and often per component
  • Environment-specific variables, not copy-pasted code
  • Plan in CI on pull requests, apply with approvals
  • Pin provider and module versions; limit blast radius

Model answer

I put shared building blocks such as the network, the Kubernetes cluster and the database into reusable modules, versioned with Git tags or a private registry. Each environment then has a small root configuration that calls those modules with its own variables, for example instance sizes or replica counts. Every environment has its own remote state with locking, and I often split state by component, like network and apps, so one bad apply cannot break everything; this limits the blast radius. Provider and module versions are pinned. In CI, every pull request runs fmt, validate, a linter and terraform plan, and posts the plan for review. Apply to production happens from the pipeline after approval, not from laptops. Tools like Terragrunt or Terraform Stacks can reduce repetition when there are many environments.

Can you answer it under time pressure?

Take a timed medium round and get scored on every answer.

Start mock interview

More medium DevOps Engineer questions