25 QuestionsDevOps & Cloud
Terraform Interview Questions
25 Terraform questions from real interviews, sorted by seniority: state and locking, modules, count against for_each, provisioners, backend architecture and drift.
State Locking & S3/DynamoDBfor_each vs countModules & DRYTerraform Plan vs ApplyDrift DetectionWorkspaces
Showing 25 of 25 questions
•
#1
What problem does Terraform solve that a shell script does not?
Junior
Junior
Terraform is declarative and stateful. You describe the infrastructure you want, and it works out the difference between that and what exists, then makes only the changes needed. A script is imperative: it describes steps, and running it twice does something different from running it once.
That gives you three things a script does not:
- A plan you can review before anything changes.
- Idempotence, so converging on the desired state is safe to repeat.
- A dependency graph built from references between resources, so it knows a subnet needs its VPC first without you ordering the calls by hand.
It also spans providers, so one configuration can cover AWS, Cloudflare DNS and a GitHub repository in the same apply.
#2
Walk me through terraform init, plan and apply.
Junior
#3
What is the Terraform state file and why does it matter?
Junior
#4
What is the difference between a Terraform variable, a local and an output?
Junior
#5
How do you manage Terraform state for a team, and what does locking do?
Mid
#6
When would you use <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">terraform import</code>, and what does it not do?
Mid
#7
What makes a good Terraform module?
Mid
#8
When would you use <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">for_each</code> rather than <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">count</code> in Terraform?
Mid
#9
What is Terraform drift, and how do you handle it?
Mid
#10
Why lock provider versions, and what does the lock file do?
Mid
#11
Terraform says the state is locked. What do you do?
Mid
#12
What is the precedence order for setting Terraform variables?
Mid
#13
How do you structure Terraform state across environments, and what are the trade-offs?
Senior
#14
Someone deleted the Terraform state file. Walk me through recovery.
Senior
#15
What does the Terraform <code class="rounded-none bg-slate-100 px-1 py-0.5 font-mono text-[0.9em] text-slate-900">lifecycle</code> block give you, and when is each part the right tool?
Senior
#16
How do you run Terraform in CI safely?
Senior
#17
Terraform state holds secrets in plain text. What do you actually do about it?
Senior
#18
How do you upgrade a widely used module without breaking its consumers?
Senior
#19
A terraform plan shows a resource being destroyed and recreated that you did not change. Why?
Senior
#20
What is the difference between a Terraform data source and a resource?
Mid
#21
How do you deploy the same Terraform configuration to two regions or accounts?
Mid
#22
What does it mean that Terraform builds a dependency graph?
Junior
#23
How would you introduce Terraform to infrastructure that was all built by hand?
Senior
#24
How do you debug a provider error that is not obvious from the plan?
Mid
#25
Which Terraform files should and should not be in version control?
Junior