1049 words
5 min read

10 Real Terraform Interview Questions (and Expert Answers!) — 2025 DevOps Guide

By · Docker Captain · CNCF Ambassador · IBM Champion
Pour-over coffee setup with a black goose-neck kettle and Chemex glass carafe on a wooden serving board, soft warm light, blurred home-office bookshelf and monitor in the background

You know the line that makes engineers sweat:

“You’ve got a Terraform interview tomorrow. You ready?”

Relax.

Here are 10 Terraform questions that show up in actual interviews, plus how to answer them without flailing.

But the answers matter more than the questions. I’ll explain each one plainly, with real examples, so you don’t just parrot back a definition. You’ll actually get it.

Question 1: What is Terraform and why does it matter?#

Terraform is how you talk to your infrastructure with code instead of clicks.

You’re not poking around the AWS console at 3 a.m. like it’s 2009.

You write code. Something like: “I need a VPC, three subnets, and a database.”

And Terraform answers: “Got it. I’ll build it. I’ll check it. And I’ll keep it that way.”

Convenience is the small part. The real win is control, and repeatability. That’s the whole point of infrastructure as code.

As of 2025, Terraform sits at version 1.11. Actively developed, widely deployed, and still the default tool for defining infrastructure.

Question 2: How does Terraform talk to the cloud?#

Through providers.

Think of a provider as an adapter. It knows how to speak to a given API:

You declare required_providers in your code. Run terraform init, and it pulls the right versions, then verifies their SHA-256 hashes.

terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.97.0"
}
}
}
provider "aws" {
region = "us-west-2"
}

The .terraform.lock.hcl file pins those versions in place.

provider "registry.terraform.io/hashicorp/aws" {
version = "5.97.0"
constraints = "~> 5.97.0"
hashes = [
"h1:aaa111...",
"h1:bbb222...",
"h1:ccc333..."
]
}

Same idea as package dependencies. Don’t pin them, and you’ll get surprises. Surprises in production?

Yeah. Not fun.

Question 3: What is terraform.tfstate and why is it critical?#

It’s Terraform’s memory.

The state file tracks:

  • What resources exist
  • Their IDs
  • Their attributes
  • And how they’re all wired together

Lose it, and Terraform forgets everything you’ve built. So it might decide to recreate your entire production stack from scratch.

Where do you keep state safely? Two solid options:

TIP

Never, ever commit your state file to git. Not even to a private repo. Not even “just this once.” Just… don’t.

Question 4: What is the actual function of plan, apply, destroy, and refresh?#

Read them as: preview, execute, delete, sync.

  • terraform plan: shows what will change
  • terraform apply: actually makes the changes
  • terraform destroy: deletes everything in your config
  • terraform refresh: syncs the state with reality

In the upcoming Terraform 1.12, plan runs refresh for you. No separate command.

🎯 Advice: Always run terraform plan before terraform apply.

Especially on a Friday. Especially late at night.

Especially in prod.

Question 5: What is drift, and how do you detect it?#

Drift is when your real infrastructure stops matching your code.

Say your config declares t3.micro. Then someone goes into the AWS console and bumps it to t3.large by hand.

Terraform has no idea. It only notices the gap when you run terraform plan.

So how do you catch it?

  • On HCP Terraform, you get a built-in drift detector. It can fire alerts to Slack or Teams through notifications.
  • Not on HCP Terraform or Terraform Enterprise? Then run terraform plan in CI at least once a day.

Drift isn’t a bug. It’s a warning. Someone changed something outside of Terraform.

And remember: Infrastructure as Code does not like human hands.

Question 6: What are modules and how do you use them without creating a mess?#

A module is basically a function for your infrastructure. Write it once, reuse it everywhere.

Picture a small VPC module. You run it in dev, staging, and prod. Only the IP ranges and names change. The logic underneath stays identical.

⚠️ Keep it simple: one module, one purpose. Don’t build a single module that spins up a VPC, provisions a database, and pings Slack on the side.

Once your module is solid, you’ve got options:

Question 7: Variables vs Secrets: where’s the line?#

Simple distinction. Variables and secrets are not the same thing.

Use variables for anything that changes between environments.

Secrets are another matter. Never hardcode them. Ever.

I’ve watched this happen on real projects. Don’t be the person who writes:

password = "supersecret123"

So where do secrets belong?

If you do pass a secret as a variable, set sensitive = true.

That keeps it out of the terraform plan output.

variable "db_password" {
description = "Database password"
type = string
sensitive = true
}

And since Terraform 1.10, you can use short-lived values to keep secrets out of your state files entirely.

Question 8: What if terraform apply fails halfway through?#

It happens. To junior devs, to senior engineers, to me.

Here’s the recovery, step by step:

  1. Run terraform state list to see what was created.
  2. If the resource exists in the cloud but not in the state, use terraform import.
  3. If it shouldn’t exist, remove it from state with terraform state rm.
  4. Then re-run terraform plan and check that everything looks clean.

Terraform now supports moved and removed blocks. So you can refactor without hand-editing the state file. Less risk, no manual hacking, clean refactors. Nice.

Question 9: How do you separate dev, stage, and prod?#

Three approaches that hold up in practice:

  1. Workspaces: simple, but hard to scale
  2. Folder structure like environments/dev, stage, prod: the golden standard
  3. Terragrunt: great for multi-account or multi-team setups

🧠 Whatever you pick, one rule is non-negotiable:

🎯 One backend → one state → one environment.

Never mix dev and prod in the same state file. That’s storing fire and gasoline in the same drawer.

Question 10: How do you shift security left?#

Security isn’t a step you bolt on later. It starts at terraform plan.

That’s where Policy as Code earns its keep. Tools like:

…catch problems before they ship.

🔒 For example:

You write a rule: “All S3 buckets must use KMS.” Wired up correctly, Terraform checks that during the plan. Rule fails, run blocked.

Some of these tools live in your CI pipeline. Others plug straight into HCP Terraform.

Want to push further? terraform test lets you write unit tests for your modules, and it drops right into CI.

Security belongs in how you build, not in a cleanup you do afterward.

Final Thoughts#

That’s the set. 10 questions, 10 real answers. Not to help you scrape through an interview, but to walk in confident, prepared, and dangerously well-informed.

Thank you for reading! Don’t forget to check out the video version for additional insights and visuals.


Vladimir Mikhalev

Docker Captain  ·  CNCF Ambassador  ·  IBM Champion

The Verdict — production-tested analysis on YouTube.

The Verdict

Inconvenient truths about shipping in the AI era

Container security, platform engineering, and the agentic shift — tested in production, argued without the hype. The verdict reaches your inbox the moment there's one worth sending.

Related Posts

Same category
  1. 1
    Restore Drills on a Clean Machine — Measured RTO for 47 Stacks, 19 Seconds to 7 Minutes
    DevOps & Cloud · Restore drills that measure RTO on a machine that never ran the stack, 47 templates weekly. Every same-host restore passed. The first clean one answered 500.
  2. 2
    Mutation Testing for Infrastructure Code — 153 Planted Bugs, Four Tests That Could Not Fail
    DevOps & Cloud · Mutation testing for infrastructure code, done by hand across fifteen repositories. 153 planted bugs, and four green tests that could never have failed.
  3. 3
    Docker Health Checks That Cannot Fail — Seventeen Hours Green
    DevOps & Cloud · A Docker health check whose pattern matches the shell running it can never go red. How to find the checks in your fleet that never failed, and prove each one.
  4. 4
    Terraform MCP server GA: the Apply Gate your auditor will ask about
    DevOps & Cloud · HashiCorp's Terraform MCP server is GA and IBM Bob can write production IaC. ENABLE_TF_OPERATIONS separates a safe assistant from autonomous apply.

Random Posts

Random
  1. 1
    Install Terraform on macOS
    DevOps & Cloud · Learn how to install Terraform on macOS using Homebrew. Step-by-step guide includes setup, version check, and usage tips for managing infrastructure as code.
  2. 2
    Master Container Security in 2025 — Best Practices & Live Demo
    DevOps & Cloud · Master container security in 2025 with proven Docker & Kubernetes best practices. Learn how to automate scans using Docker Scout & Snyk with real demos.
  3. 3
    Install Exchange Server 2019 on Windows Server 2019
    SysAdmin & IT Pro · Step-by-step guide to install Exchange Server 2019 on Windows Server 2019, including prerequisites, Active Directory setup, and admin tips.
  4. 4
    Top 10 DevOps Tools for 2025 — Must-Have for Developers and Engineers
    DevOps & Cloud · Explore the top 10 DevOps tools for 2025 to optimize workflows, enhance security, and streamline CI/CD, GitOps, and Kubernetes.
10 Real Terraform Interview Questions (and Expert Answers!) — 2025 DevOps Guide
https://heyvaldemar.com/10-real-terraform-interview-questions-and-expert-answers-2025-devops-guide/
Author
Vladimir Mikhalev
Published
2025-05-12
Updated
2026-08-24
License
CC BY-NC-SA 4.0