10 Real Terraform Interview Questions (and Expert Answers!) — 2025 DevOps Guide
By Vladimir Mikhalev · Solutions Architect · Docker Captain · IBM Champion
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:
- AWS,
- Azure,
- Kubernetes,
- GitHub,
- and tons more.
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:
- 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?
Read them as: preview, execute, delete, 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 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 planin 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:
- 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?
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:
- 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 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:
- 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
🧠 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:
- OPA (Open Policy Agent)
- Sentinel (by HashiCorp)
- Checkov (by Bridgecrew)
- Snyk IaC
…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.
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
- 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 and Configure DHCP Server on Windows Server 2012 R2SysAdmin & IT Pro · Step-by-step guide to install and configure a DHCP server on Windows Server 2012 R2. Learn to assign IPs, set exclusions, and reserve addresses with ease.
- 2Join Windows Server 2019 Server Core to a DomainSysAdmin & IT Pro · Step-by-step guide to joining Windows Server 2019 Server Core to a domain using PowerShell. Ideal for IT pros managing Active Directory environments.
- 3Docker Init The Future of Easy Project InitializationDevOps & Cloud · Learn how to use Docker Init to quickly generate Dockerfiles, .dockerignore, and Compose files. Simplify container setup for Go, Node, Python, and more.
- 4Install GLPI Using Docker ComposeSelf-Hosting · Learn how to install GLPI using Docker Compose with Traefik and Let's Encrypt. Set up your open-source IT asset management and service desk system step-by-step.