What is Terraform state, why does it exist, and what goes wrong if two people apply at the same time?
What they are really testing: State is where most real Terraform pain lives. They want to know you understand it as a mapping, and that you know about locking and why state files are sensitive.
A real interview question
What is Terraform state, why does it exist, and what goes wrong if two people apply at the same time?
What most people say
drag me
“It is a file that keeps track of what Terraform created.”
Correct as far as it goes, but it stops before every consequence that matters: locking, remote backends, secrets in state, and what to do when it drifts. The follow-up will immediately expose the gap.
The follow-ups they ask next
Someone deleted a resource in the console. What does Terraform do next run?
Plan shows it as needing creation, because state says it exists and reality says otherwise. That is drift. Either let it recreate, or refresh state and import if the real thing should be kept.
How do you bring an existing manually-created resource under Terraform?
Write the matching configuration, then terraform import to bind it to that address, then plan until it shows no changes. Recent versions support import blocks so it can be reviewed as code.
What the interviewer is listening for
- Describes state as a mapping
- Names locking and remote backends
- Knows state can contain plaintext secrets
What sinks the answer
- Suggests committing state to git
- Unaware of locking
- Cannot explain drift
If you genuinely do not know
Say this instead of freezing. Reasoning out loud from what you do know beats silence every single time, and a good interviewer is listening for exactly that.
“State maps [config blocks to real resources] so Terraform can [diff instead of recreating]. Two applies at once [race and can corrupt state or orphan resources]. Fix with [remote backend plus locking and versioning]. Also [state holds plaintext secrets, so encrypt it and keep it out of git].”
Keep going with infrastructure as code
Foundation
What is infrastructure as code, and why is it better than clicking in a console?
Mid
Terraform plan wants to destroy a production database that someone modified manually. What do you do?
Senior
How would you structure Terraform for 40 services across 3 environments? What goes wrong with the obvious approaches?
Junior
Design the pipeline for a typical web application. What stages would you have, and in what order?
Junior
Our Docker image is 1.2 GB and takes 8 minutes to build. How would you make it smaller and faster?
Junior
Explain the relationship between a Pod, a Deployment, and a Service in Kubernetes.
Knowing the answer is not the same as recalling it under pressure
Sign in to send the questions you fumble to spaced recall, so they come back right before you would forget them, and learn the concepts behind them with hands-on labs.
Start free