Courseiva
Implement and maintain stateeasyMultiple ChoiceObjective-mapped

TF-004 Implement and maintain state Practice Question

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?

⚠ Common exam trap

A common misconception is that `terraform apply` or `terraform state push` can handle backend migration, but only `terraform init` performs the full initialization and state migration workflow.

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

`terraform init`

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.

Answer analysis

Option-by-option breakdown

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

  • `terraform plan`

    Why it's wrong here

    The `terraform plan` command generates an execution plan, showing what actions Terraform will take to achieve the desired state defined in your configuration files. It is a read-only operation that does not modify the infrastructure, the local state file, or configure a remote backend. Therefore, it cannot be used to initialize or migrate state to a new remote backend for the first time.

  • `terraform init`

    Why this is correct

    The `terraform init` command is essential for preparing a working directory for Terraform operations, which includes configuring the backend. When a backend configuration is present for the first time, `init` detects it, initializes the connection, and crucially, prompts the user to migrate any existing local state file to the newly configured remote backend. This makes it the correct and primary command for setting up remote state.

  • `terraform apply`

    Why it's wrong here

    The `terraform apply` command executes the actions proposed in a `terraform plan`, making real changes to your infrastructure. It relies on an already initialized backend and an existing state file to track resources. This command does not handle the initial setup or migration of state to a remote backend; its purpose is solely to provision or modify resources based on the current configuration and state.

  • `terraform state push`

    Why it's wrong here

    The `terraform state push` command allows for manually uploading a local state file to a configured remote backend. While it can transfer a state file, it is not the standard or recommended method for the *initial* migration when setting up a remote backend for the first time. `terraform init` handles the entire backend configuration and offers a guided, safer migration process, making `state push` a specialized, less common operation for this specific scenario.

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

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.