You have existing infrastructure created by hand. How do you bring it under Terraform management?
What they are really testing: Senior/brownfield signal: knows you must import resources into state and write matching config, that it is iterative and verified with plan, rather than recreating everything.
A real interview question
You have existing infrastructure created by hand. How do you bring it under Terraform management?
What most people say
drag me
“I would write the Terraform code and run it to take over the resources.”
Just applying new code would try to create duplicates or conflict with the existing resources, not adopt them. You must import them into state and write config that matches, then iterate to a zero-diff plan. The import step is the whole point.
The follow-ups they ask next
Why is a "zero-diff" plan the goal after importing?
It proves your written config exactly matches the real resource, so Terraform will not try to change or destroy it on the next apply. Any diff means your code does not yet reflect reality and would alter the resource.
Does terraform import write the configuration for you?
No, import only adds the resource to state. You still hand-write (or generate) matching config; without it, the next plan would propose changes/destroys. Newer import blocks and tooling can help generate config, but you verify with plan.
What the interviewer is listening for
- Imports into state rather than recreating
- Knows import does not write config
- Iterates to a zero-diff plan, works incrementally
What sinks the answer
- Would apply new code and recreate
- Thinks import writes config
- No verification via plan
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.
“Adopt, do not recreate: [terraform import (or import blocks) records each existing resource in state]. Then [write config matching the real attributes, since import does not write config], and [run plan and adjust until it shows zero changes, the zero-diff plan proves your code matches reality]. Work [incrementally, lower-risk first, use tooling like Terraformer to bootstrap], verifying each with plan.”
Keep going with iac & automation
Foundation
What is Infrastructure as Code, and why use it instead of clicking through the console?
Foundation
What is the difference between declarative and imperative infrastructure as code?
Junior
What is Terraform state, and why does it exist?
Junior
Explain the Terraform workflow: init, plan, and apply.
Mid
Your team provisions infrastructure with code. Why does idempotency matter, and what breaks without it?
Mid
Why do teams use remote state with locking instead of local state?
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