Courseiva
Understand Terraform's purposemediumMultiple ChoiceObjective-mapped

TF-004 Understand Terraform's purpose Practice Question

During a terraform apply, the state file becomes corrupted. What is the recommended recovery method?

⚠ Common exam trap

The misconception tested in this question is that Terraform has a built-in repair command like `terraform state pull` or that re-running `terraform apply` can recover from corruption. In reality, the only reliable recovery method is restoring from a known good backup of the state file.

Answer choices

Why each option matters

Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.

Correct answer & explanation

Restore from backup

The recommended recovery method for a corrupted Terraform state file is to restore it from a known good backup. Terraform does not have built-in corruption repair mechanisms, so maintaining regular backups of the state file (e.g., using remote backends with versioning like S3 versioning or Terraform Cloud) is the standard operational practice. Restoring from backup ensures the state accurately reflects the real-world infrastructure without manual intervention.

Answer analysis

Option-by-option breakdown

For each option: why learners choose it and why it is or isn't the right answer here.

  • Restore from backup

    Why this is correct

    When a Terraform state file becomes corrupted, the most reliable and recommended recovery strategy is to restore it from a recent, uncorrupted backup. Remote state backends, such as AWS S3 or Azure Blob Storage, automatically version and store previous states, making restoration straightforward. This approach ensures the state accurately reflects the infrastructure, preventing drift and potential resource destruction or recreation during subsequent `terraform apply` operations. It minimizes data loss and operational disruption, maintaining infrastructure integrity.

  • Re-run apply

    Why it's wrong here

    Re-running `terraform apply` with a corrupted state file is highly dangerous and should be avoided. A corrupted state cannot accurately map real-world resources to the configuration, leading Terraform to misinterpret the infrastructure's current status. This can result in unintended resource destruction, creation of duplicate resources, or significant configuration drift, making the infrastructure unmanageable and potentially causing service outages.

  • Delete the state and re-import all resources

    Why it's wrong here

    Deleting the corrupted state file and attempting to re-import all existing resources is an extremely labor-intensive and error-prone process, especially for complex infrastructures. Each resource would need to be individually identified and imported using `terraform import`, requiring precise resource addresses and IDs. This method is highly susceptible to human error, can easily miss resources, and is significantly more time-consuming than restoring from a backup, making it impractical for recovery.

  • Use terraform state pull

    Why it's wrong here

    The `terraform state pull` command is used to retrieve the current remote state and output it to standard output or a local file. While it fetches the state, it does not possess any inherent capability to detect or repair corruption within that state file itself. If the remote state is already corrupted, pulling it locally will simply retrieve the corrupted version, offering no solution to the underlying problem of state integrity.

Quick reference

AWS S3 Storage Class Comparison

Storage ClassMin DurationRetrievalUse Case
S3 StandardNoneImmediateFrequently accessed data
S3 Standard-IA30 daysImmediateInfrequent access, rapid retrieval
S3 One Zone-IA30 daysImmediateNon-critical infrequent data
S3 Intelligent-TieringNoneImmediate–hoursUnknown or changing access patterns
S3 Glacier Instant90 daysMillisecondsArchive with instant retrieval
S3 Glacier Flexible90 daysMinutes–hoursArchive, flexible retrieval
S3 Glacier Deep Archive180 daysHoursLong-term compliance archive

About these practice questions

One of 428 original TF-004 practice questions on Courseiva, each with a full explanation and wrong-answer analysis — not exam dumps or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

JA

Written by Johnson Ajibi, MSc IT Security

Senior Network & Security Engineer · founder of Courseiva

This TF-004 practice question is part of Courseiva's free HashiCorp certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the TF-004 exam.