Interview Q&A · questions with model answers

Terraform Interview Questions

Part of the study plan for: DevOps Engineer · Cloud Engineer · Site Reliability Engineer (SRE)

Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.

  1. Most asked Terraform apply fails halfway through — some resources were created, others were not. How do you recover?

    Don't panic and don't re-run blindly. Terraform records each resource it successfully created in state as it goes, so the state file already reflects the partial progress. Run terraform plan again —…

  2. Most asked Someone manually deletes an EC2 instance that Terraform manages. What happens on the next plan and apply?

    Terraform refreshes state against real infrastructure and discovers the instance is gone. The plan shows the instance will be created again. Apply recreates it. The manual deletion is effectively…

  3. What happens if two engineers apply at the same time without state locking?

    Both reads succeed, both compute a plan against the same snapshot, and both try to write back. One write overwrites the other, so the state file no longer reflects what actually exists: resources…

  4. How would you recover a corrupted or lost Terraform state file?

    If the backend has versioning (S3 bucket versioning), restore the previous state version. If not, rebuild state by running terraform import for every resource the configuration manages. Prevention…

  5. What happens if the CI runner crashes or loses connectivity during terraform apply?

    The in-progress API call either completes or fails on the AWS side — Terraform has no way to cancel it. The state lock remains held until it expires or you force-unlock it. The state file may or may…

  6. The Terraform state lock is stuck. How do you handle it?

    First confirm no apply is actually running (check CI jobs and colleagues), because removing a lock during a running apply can corrupt state. If the lock is genuinely stale (a crashed run), release…

Was this page helpful?

Report a mistake