Terraform · Infrastructure as code

How does Terraform fit into disaster recovery?

Harddisaster recoverystate recoveryrtoUpdated Oct 2026
Quiz this track

Short answer

Terraform helps rebuild infrastructure only if configuration and state are recoverable. Version and replicate state, keep code in durable version control, and rehearse restore so you know your real RTO.

Configuration is the recipe, state is the map, and the cloud is the running system. Disaster recovery needs all three. If the code is gone, you cannot rebuild consistently. If state is gone, Terraform no longer knows what it owns, even though the resources may still exist.

sh
terraform state pull > backup.tfstate
aws s3api list-object-versions --bucket acme-tfstate --prefix prod/terraform.tfstate
terraform state push backup.tfstate
Pull a state backup and inspect versioned objects before restoring. Confirm the serial and lineage before pushing.

Failure modes to plan for

  • State bucket deleted or corrupted: restore a versioned object
  • State lost but resources alive: re-import into rebuilt configuration
  • Region outage: apply a standby configuration to another region
  • Provider or registry outage: mirror providers and modules internally
  • Credential loss: recover break-glass access outside the normal pipeline

A rebuild is not a data-recovery strategy. Terraform can recreate a database, but it cannot recreate the rows unless backups exist. Pair infrastructure recovery with data backups, DNS failover and documented dependency order. Measure RTO and RPO with a real exercise, not a theoretical diagram.

Keep a break-glass procedure that does not depend on the same CI or identity provider that might be part of the outage. Test it before you need it.

Follow-ups you should expect

Interviewers use these to check whether the first answer was understanding or memorisation.

  1. 1What happens if state is lost but the resources still exist?
  2. 2How do you recover a corrupted state file?
  3. 3Why is Terraform not a data backup tool?
  4. 4What would you include in a DR exercise?

Say it in the interview

Terraform supports disaster recovery by encoding how to rebuild infrastructure, but only if the code and state are recoverable. I version and replicate state, keep modules available even during a registry outage, and document a break-glass path. If state is lost but resources exist, I re-import rather than recreate blindly. I also pair it with real data backups, because Terraform cannot restore database contents.

Use this as a model, not a script. Saying it in your own words is what makes it survive follow-up pressure.

Related questions

Reading is step one

Now say it out loud.

Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live Terraform mock interview and get scored feedback on depth, clarity and confidence.