Terraform interview question · Most asked

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

Scenario Asked in DevOps Engineer · Cloud Engineer · Site Reliability Engineer (SRE) interviews

Members can save this page, take notes and track progress. See membership · Sign in

Summary

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 — it will show a plan that creates only the remaining resources and leaves the already-created ones alone.

Longer Answer

Terraform updates the state file after each resource operation, not at the end. If apply creates resources A, B, and C in order and fails on C:

  1. A and B are in state — Terraform knows they exist and won't try to recreate them.
  2. C is not in state — the next plan will attempt to create it again.

Recovery steps:

  1. Read the error message. The most common causes are: API rate limits, permission errors, resource limits (e.g. max VPCs), invalid arguments that the provider couldn't validate at plan time, or a dependency that doesn't exist yet (eventual consistency).
  2. Fix the root cause. Request a limit increase, fix the IAM policy, correct the argument.
  3. Run terraform plan. It shows only the remaining changes. Review them.
  4. Run terraform apply. It picks up where it left off.

Edge cases:

  • Resource created but not recorded in state (rare — Terraform crashed between the API call and the state write): the next apply creates a duplicate. Fix with terraform import for the orphan and terraform state rm for the duplicate address.
  • Resource partially created (e.g. an RDS instance that started provisioning but failed): check the AWS console. If the resource exists in a failed state, delete it manually or import it and let Terraform recreate it.
  • State lock not released (Terraform process killed): run terraform force-unlock <LOCK_ID> after confirming no other apply is running.

What not to do:

  • terraform destroy and start over — this deletes the resources that were created successfully, including any data they hold.
  • Edit the .tf files to remove the failed resource — this makes Terraform think the successfully created resources should also be destroyed.

Key Points

  • Terraform writes to state after each resource, so partial progress is preserved
  • Run terraform plan after a failure — it shows only the remaining work
  • Fix the root cause (permissions, limits, arguments) before retrying
  • Never destroy-and-recreate or remove resources from config to work around a partial failure

Explanation

What interviewers look for

Look for understanding that state captures partial progress. Weak answers suggest destroying everything and starting over. Strong answers explain the incremental state model and mention edge cases like orphaned resources or stuck locks.

More Terraform questions

← All Terraform questions

Last reviewed · By the ByteCamel team · How we write content

Was this page helpful?

Report a mistake