Courseiva
Understand Terraform's purposehardMultiple ChoiceObjective-mapped

TF-004 Understand Terraform's purpose Practice Question

A DevOps team accidentally deleted their Terraform state file. The actual infrastructure (EC2 instances, security groups, etc.) is still running and unchanged. They have the Terraform configuration files that were used to create the infrastructure. They want to re-establish management of the existing infrastructure without recreating it. Which course of action aligns with Terraform's purpose?

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

Use terraform import for each resource to bring them into the state file.

Terraform's purpose includes managing existing infrastructure through import. Using terraform import allows you to bring resources into state without recreation. Deleting and recreating is disruptive, and modifying config without state is risky.

Answer analysis

Option-by-option breakdown

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

  • Delete all existing infrastructure and run terraform apply to recreate it.

    Why it's wrong here

    Deleting all existing infrastructure and then running terraform apply to recreate it would result in significant, unnecessary downtime and potential data loss for any stateful services. While this approach would technically restore a functional environment, it completely disregards the existing, operational resources. Terraform's purpose is to manage infrastructure efficiently, and a full tear-down and rebuild is an extreme measure that should only be considered if the existing infrastructure is entirely irrecoverable or deemed obsolete.

  • Manually edit the configuration to match the existing resources exactly, then run terraform apply.

    Why it's wrong here

    Manually editing the Terraform configuration to perfectly match the existing resources, then running terraform apply, would not resolve the missing state issue. Without a state file, terraform apply would interpret the configuration as a request to create *new* resources corresponding to the defined blocks. This would lead to errors, as the resources already exist in the cloud provider, or potentially create duplicate resources if the provider allows it, causing resource sprawl and management headaches.

  • Run terraform plan to generate a new state file automatically.

    Why it's wrong here

    Running terraform plan does not generate a new state file automatically; its primary function is to compare the current Terraform configuration with the *existing* state file and the actual infrastructure. It then proposes a set of changes required to bring the infrastructure into alignment with the configuration. Without a state file, terraform plan would effectively see all resources defined in the configuration as "to be created," but it would not persist this information into a new state file.

  • Use terraform import for each resource to bring them into the state file.

    Why this is correct

    Using terraform import for each resource is the correct and most robust method to recover from a lost state file without disrupting existing infrastructure. This command allows you to link an existing cloud resource, identified by its provider-specific ID, to a corresponding resource block defined in your Terraform configuration. By systematically importing each managed resource, Terraform rebuilds its state file, establishing a new authoritative record of the infrastructure it controls.

About these practice questions

Courseiva writes every TF-004 question from scratch — 428 in total, each with an explanation and a wrong-answer breakdown. None are copied from real exams or dumps. 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.