Courseiva
Implement and maintain statemediumMultiple SelectObjective-mapped

Migrate Terraform State to Remote Backend

Which THREE actions should be taken when migrating Terraform state from local to a remote backend?

Quick Answer

The answer is to add a backend block to the configuration, because this block defines the remote storage location and triggers Terraform’s built-in migration workflow. When you run `terraform init` after adding the block, Terraform detects the change and automatically prompts you to copy the existing local state file to the new remote backend, handling the entire migration seamlessly without manual file manipulation. On the HashiCorp Terraform Associate TF-003 exam, this concept tests your understanding of state management and backend initialization—a common trap is thinking you need to manually move or copy the `terraform.tfstate` file, but `terraform init` does this for you. The exam often presents a scenario where you must identify the correct sequence: add the backend block, then run `terraform init` and type "yes" to confirm migration. Memory tip: "Block first, then init—Terraform handles the lift."

⚠ Common exam trap

HashiCorp often tests the misconception that you must manually delete or move the local state file before initializing a remote backend, when in fact `terraform init` handles the migration automatically and safely.

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

Run terraform init to initialize the backend and migrate state.

`terraform init` is the command that initializes the backend configuration and, when a backend block is added to the configuration, automatically prompts to migrate the existing local state file to the new remote backend. This command handles the state migration seamlessly without requiring manual intervention, ensuring the state file is copied and the backend is configured correctly.

Answer analysis

Option-by-option breakdown

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

  • Remove the local state file before running terraform init.

    Why it's wrong here

    Terraform init uses the local state for migration; removing it would lose data.

  • Run terraform init to initialize the backend and migrate state.

    Why this is correct

    This command handles the migration.

  • Manually import all existing resources into the remote state.

    Why it's wrong here

    Resources are already in local state; no import needed.

  • Confirm migration by typing 'yes' when prompted.

    Why this is correct

    Terraform prompts for confirmation before overwriting remote state.

  • Add a backend block to the configuration.

    Why this is correct

    Required to define 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

Same concept, more angles

1 more way this is tested on TF-004

These questions test the same concept from different angles. Work through them to make sure you can recognise it however the exam phrases it.

Variation 1. A user wants to use a remote state backend for the first time. After adding the backend configuration, which command must they run to migrate the state from local to remote?

easy
  • A.`terraform plan`
  • B.`terraform init`
  • C.`terraform apply`
  • D.`terraform state push`

Why B: When you add a remote backend configuration to your Terraform code, `terraform init` is the required command to initialize the backend and migrate the existing local state file to the remote backend. During initialization, Terraform detects the backend change, prompts for confirmation, and automatically copies the state from the local `terraform.tfstate` to the configured remote store (e.g., S3, Azure Storage, or Terraform Cloud). Without running `init`, the remote backend is not configured and local state remains unchanged.

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.