Courseiva
Question 59 of 428
Implement and maintain statehardMultiple ChoiceObjective-mapped

TF-004 Implement and maintain state Practice Question

A team is migrating from local state to an S3 remote backend. They have existing state files in the working directory. After configuring the backend block and running `terraform init`, what is the correct next step to migrate the existing state?

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

Execute `terraform init` and confirm yes when prompted to copy existing state

When migrating from local to remote state, Terraform automatically prompts to copy existing state during `terraform init` if the backend block changes. Selecting 'yes' will migrate the state. Option A correctly describes this process.

Answer analysis

Option-by-option breakdown

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

  • Execute `terraform init` and confirm yes when prompted to copy existing state

    Why this is correct

    When migrating from a local state to a remote backend like S3, `terraform init` is the authoritative command. It detects the change in the `backend` configuration block within your `.tf` files. Upon execution, Terraform prompts the user to confirm the migration, offering to copy the existing local `terraform.tfstate` file to the newly configured remote backend, ensuring a seamless and consistent transition of the state management.

  • Run `terraform state push` to upload the local state

    Why it's wrong here

    The `terraform state push` command, while historically present, is now deprecated and not the correct method for migrating an entire backend. Its primary function was to upload a *local* state file to an *already configured* remote backend, not to initiate or manage the backend configuration change itself. Relying on this command for a backend migration would bypass Terraform's built-in safety mechanisms and proper backend initialization process, potentially leading to an unmanaged or inconsistent state.

  • Delete the local state file and run `terraform apply` to recreate

    Why it's wrong here

    Deleting the local `terraform.tfstate` file before running `terraform apply` is highly destructive and fundamentally misunderstands Terraform's state management. Without a state file, Terraform loses all knowledge of the infrastructure it previously provisioned. A subsequent `terraform apply` would then attempt to create *new* resources based on the configuration, leading to resource duplication, errors if resources already exist, or even the destruction and recreation of existing infrastructure, rather than a controlled migration.

  • Manually copy the state file to S3 using AWS CLI

    Why it's wrong here

    Manually copying the `terraform.tfstate` file to an S3 bucket using the AWS CLI is insufficient because it only moves the file, not the backend configuration. Terraform itself would remain unaware of this manual action and would still expect to find the state either locally or at its previously configured location. This approach fails to update Terraform's internal understanding of the backend, resulting in a 'state not found' error or the creation of a new, empty state file in S3, thereby breaking the critical link between the configuration and the actual infrastructure state.

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 creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →

How Courseiva writes practice questions · Editorial policy

Last reviewed: Jun 24, 2026

Question Discussion

Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.

Loading comments…

Sign in to join the discussion.

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.