10 Real Terraform Interview Questions (and Expert Answers!) — 2025 DevOps Guide
By Vladimir Mikhalev · Solutions Architect · Docker Captain · IBM Champion
I know the kind of phrase that makes engineers panic:
“You’ve got a Terraform interview tomorrow. You ready?”
Take a breath.
Today, I’m sharing 10 Terraform questions that actually come up in real interviews — and how to answer them like a pro.
But more importantly, I’ll explain them clearly, practically, and with real-life examples, so you don’t just memorize the answers — you understand them.
Alright, let’s dive in.
Question 1: What is Terraform and why does it matter?
Terraform is how you talk to your infrastructure — with code, not clicks.
You’re not clicking around AWS at 3 a.m. like it’s 2009.
You’re writing code:
“I need a VPC, three subnets, and a database.”
Terraform says:
“Got it. I’ll build it. I’ll check it. And I’ll make sure it stays that way.”
It’s not just convenient — it’s control. It’s repeatability. It’s infrastructure as code.
As of 2025, Terraform is at version 1.11, actively developed and widely used. It remains the industry standard for defining infrastructure.
Question 2: How does Terraform talk to the cloud?
Terraform talks to the cloud through something called providers.
These providers are like adapters — they know how to talk to APIs like:
- AWS,
- Azure,
- Kubernetes,
- GitHub,
- and tons more.
In your code, you define required_providers, and when you run terraform init, it pulls in the right versions and 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 locks 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..." ]}Think of it like package dependencies — if you don’t pin them, expect surprises. And 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 stores:
- What resources exist
- Their IDs
- Their attributes
- And how they’re all connected
Lose it… and Terraform has no memory. It forgets everything you’ve built. Which means it might try to recreate your entire production stack — from scratch.
So where should you store your state safely?
- S3 bucket with native locking (available since Terraform 1.11)
- HCP Terraform (formerly Terraform Cloud)
TIPNever, 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?
Think of them as: preview, execute, delete, and sync.
terraform plan— shows what will changeterraform apply— actually makes the changesterraform destroy— deletes everything in your configterraform refresh— syncs the state with reality
In upcoming Terraform 1.12, plan includes refresh automatically — no need to run it separately.
🎯 Advice: Always run terraform plan before terraform apply.
Especially if it’s Friday. Especially if it’s late.
Especially if it’s prod.
Question 5: What is drift, and how do you detect it?
Drift happens when your real infrastructure no longer matches your code.
Let’s say your config says t3.micro, but someone in AWS changed it manually to t3.large.
Terraform won’t magically know. It only sees drift when you run terraform plan.
So, how do you detect drift?
- If you’re using HCP Terraform, good news — it has a built-in drift detector that can send alerts to Slack or Teams via notifications.
- If you’re not using HCP Terraform or Terraform Enterprise, make sure to run
terraform planin CI at least once a day.
Drift isn’t a bug — it’s a warning. It means someone made changes 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?
Think of a module like a function in code — write it once, reuse it everywhere.
For example, imagine you’ve got a simple VPC module. You use it in dev, staging, and prod — only the IP ranges and names change. The logic stays the same.
⚠️ Keep it simple: one module — one purpose. Don’t build a module that creates a VPC, sets up a database, and sends a Slack notification — all in one go.
Once your module is solid, you’ve got options:
- Publish it to the Terraform Registry
- Or even store it as an OCI artifact (this feature is experimental in Terraform 1.12)
Question 7: Variables vs Secrets — where’s the line?
Let’s keep it simple — variables and secrets are not the same.
Use variables for anything that changes between environments.
But secrets are a different story — never hardcode them. Ever.
I’ve seen this in real projects — don’t do this:
password = "supersecret123"So, where should you put secrets?
If you do pass a secret as a variable — make sure it’s marked as sensitive = true.
That way, it won’t show up in the terraform plan output.
variable "db_password" { description = "Database password" type = string sensitive = true}And starting with Terraform 1.10, you can now 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, senior engineers… even to me.
So here’s how you handle it — step by step:
- Run
terraform state listto see what was created. - If the resource exists in the cloud but not in the state — use
terraform import. - If it shouldn’t exist — remove it from state with
terraform state rm. - Then re-run
terraform planand verify everything looks clean.
Terraform now supports moved and removed blocks, so you can refactor without manually editing the state file. That means less risk, no manual hacking — just clean refactoring. Beautiful.
Question 9: How do you separate dev, stage, and prod?
There are three proven approaches:
- Workspaces — simple, but hard to scale
- Folder structure like
environments/dev,stage,prod— the golden standard - Terragrunt — great for multi-account or multi-team setups
🧠 But whichever method you choose, there’s one rule you should never break:
🎯 One backend → one state → one environment.
Never mix dev and prod in the same state file. That’s like storing fire and gasoline in the same drawer.
Question 10: How do you shift security left?
Security isn’t something you add later — it starts with your terraform plan.
That’s where Policy as Code comes in. Tools like:
- OPA (Open Policy Agent)
- Sentinel (by HashiCorp)
- Checkov (by Bridgecrew)
- Snyk IaC
…help you catch issues early.
🔒 For example:
You write a rule — “All S3 buckets must use KMS.” With the right setup, Terraform checks that during the plan. If it fails — the run is blocked.
Some of these tools run right in your CI pipeline, others plug into HCP Terraform directly.
Want to go deeper? terraform test lets you write unit tests for your modules — and it fits right into your CI pipeline.
Security should be part of how you build, not something you fix later.
Final Thoughts
And that’s it. 10 questions, 10 real answers — not just to help you survive an interview, but to help you 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.
Related Posts
- 1Docker supply chain hardening — from Scout D to OpenSSF 7.8 on a 730K-pull imageDevOps & Cloud · How I hardened a 730K-pull public Docker image from Scout grade D to OpenSSF Scorecard 7.8. Multi-stage build, cosign signing, SLSA provenance, non-root default, and the incident that changed how I ship attestations.
- 2Cloudflare Web Analytics on Astro — Why Removing GA4 Unlocked Lighthouse 100DevOps & Cloud · How removing Google Analytics 4 from an Astro site unlocked Lighthouse 100, why Cloudflare Web Analytics replaced it, and what the tradeoffs actually cost.
- 3Platform Engineering — The Complete, Practical Guide to Building Internal Developer Platforms That ScaleDevOps & Cloud · A deep, practical guide to Platform Engineering. Learn how to build internal developer platforms, golden paths, GitOps workflows, and scalable cloud foundations.
- 4Amazon Q vs DevOps Chaos — Can This AI Fix AWS Faster Than You?DevOps & Cloud · Fix AWS issues faster with Amazon Q, the AI assistant built for DevOps. Real-world examples, limitations, and how it compares to ChatGPT.
Random Posts
- 1Install Firmware for Kernel Drivers on UbuntuSysAdmin & IT Pro · Learn how to install firmware for kernel drivers on Ubuntu using .deb packages to ensure hardware compatibility and system stability.
- 2Install Ubuntu Server 18.04 LTSSysAdmin & IT Pro · Step-by-step guide to install Ubuntu Server 18.04 LTS. Learn disk setup, OpenSSH installation, user configuration, and post-installation steps for server deployment.
- 3Basic Setup of Windows Server 2012 R2SysAdmin & IT Pro · Step-by-step guide to setting up Windows Server 2012 R2 - hostname, RDP access, time zone, static IP, domain join, and system locale configuration.
- 4Install Mattermost Using Docker ComposeSelf-Hosting · Step-by-step guide to install Mattermost with Docker Compose. Set up secure team chat using Traefik, Let's Encrypt, and Docker on your own server.