1088 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 (deprecated)

terraform plan and terraform apply already refresh state by default. The standalone terraform refresh is deprecated. When you only want the sync, run terraform plan -refresh-only to see the drift, or terraform apply -refresh-only to write it to state.

🎯 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 CaptainCNCF AmbassadorIBM 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
    Scheduled Workflows Fail Silently: A GitHub Actions Heartbeat for 122 Repositories
    DevOps & Cloud · GitHub Actions switches off a scheduled workflow after 60 quiet days, with no failed run and no red badge. What watches every schedule, and the watcher.
  2. 2
    Completed Is Not Restored: Kyverno Fail-Open, a Velero Restore and an HTTP 200 That Meant 500
    DevOps & Cloud · Scale Kyverno to zero and its webhooks vanish. A Velero restore said Completed over an empty disk. A 200 carried a 500. Three statuses that reported success.
  3. 3
    Docker Hub Immutable Tags: The Image That Shipped Before It Was Signed
    DevOps & Cloud · Docker Hub immutable tags refused a per-commit tag after the version tags were already out. The image shipped, the run died, and nothing ever signed it.
  4. 4
    Docker Hardened Images Migration: A Healthy Database That Kept Nothing
    DevOps & Cloud · Moving a Compose stack to Docker Hardened Images changes user IDs, paths and tools. On the old mount path, PostgreSQL stayed healthy and kept nothing.

Random Posts

Random
  1. 1
    AI Didn't Fix Productivity. Measurement Did.
    Opinion & Culture · AI adoption is easy. Proving productivity isn't. A Docker Captain's view on why AI impact is hard to measure—and how teams can finally prove real value.
  2. 2
    Future-Proofing JavaScript with ESM and CJS Compatibility Techniques
    DevOps & Cloud · Master ECMAScript Modules (ESM) and CommonJS (CJS) in NPM packages — key compatibility strategies for effective JavaScript development.
  3. 3
    Install OTRS on Ubuntu Server
    SysAdmin & IT Pro · Guide to installing OTRS Community Edition on Ubuntu Server — configure PostgreSQL, Apache, and SSL with Let's Encrypt, and launch OTRS securely.
  4. 4
    Install Windows Admin Center on Windows Server 2019 Server Core
    SysAdmin & IT Pro · Install Windows Admin Center on Windows Server 2019 Server Core — a PowerShell guide covering domain setup, secure access, and server management.
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