Courseiva
Implement and maintain stateeasyMultiple SelectObjective-mapped

TF-004 Implement and maintain state Practice Question

Which TWO of the following are valid strategies to migrate Terraform state from a local backend to a remote backend?

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

Manually copy the local state file to the remote backend storage

The valid strategies for migrating state from local to remote backend are: manually copying the state file to the remote location (B) or using `terraform init -migrate-state` (D). Option C is incorrect because `terraform init -reconfigure` only reconfigures the backend without migrating the existing state.

Answer analysis

Option-by-option breakdown

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

  • Use terraform import for each resource

    Why it's wrong here

    Using `terraform import` for each resource is not a valid state migration strategy. The `terraform import` command is designed to bring existing, unmanaged infrastructure under Terraform's control by creating new state entries from live resources. It does not facilitate the transfer or update of an existing `terraform.tfstate` file from a local backend to a remote one, making it an entirely inappropriate and highly tedious method for state migration.

  • Manually copy the local state file to the remote backend storage

    Why this is correct

    Manually copying the local state file (`terraform.tfstate`) to the remote backend storage location is a valid, albeit less automated, strategy. This approach requires direct interaction with the remote storage system (e.g., uploading to an S3 bucket or Azure Blob Storage). After the manual copy, you must then run `terraform init` (without the `-migrate-state` flag, as the state is already present) to configure Terraform to recognize and use the state file now residing in the remote backend.

  • Change backend configuration and run terraform init -reconfigure

    Why it's wrong here

    Changing the backend configuration and running `terraform init -reconfigure` is insufficient for state migration. The `-reconfigure` flag instructs Terraform to discard any existing backend configuration and reinitialize based solely on the current `backend` block in your configuration. It does not automatically transfer the content of your local `terraform.tfstate` file to the newly configured remote backend; it would simply create an empty state file at the remote location if one doesn't exist.

  • Use terraform init with the -migrate-state flag

    Why this is correct

    Using `terraform init` with the `-migrate-state` flag is the standard and recommended method for migrating state from a local backend to a newly configured remote backend. This command automatically detects the change in backend configuration, copies the existing local `terraform.tfstate` file to the specified remote location, and then configures Terraform to use that remote backend for all subsequent operations. It ensures a seamless and automated transition, including proper state locking mechanisms.

  • Use the terraform state push command

    Why it's wrong here

    The terraform state push command is used for pushing state to a remote backend but is not intended for initial migration from local to remote; it requires the state to already be configured for the remote backend.

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.