Courseiva
Implement and maintain statehardMultiple SelectObjective-mapped

Migrate State to New S3 Bucket

A team uses an S3 backend for state storage with DynamoDB locking. They want to migrate to a new S3 bucket. Which two steps are necessary to perform a successful state migration? (Choose two.)

Quick Answer

The correct answer is to update the backend block in the Terraform configuration and then run terraform init -reconfigure. This works because Terraform’s init command automatically detects the changed backend configuration and, when used with the -reconfigure flag, copies the existing state file from the old S3 bucket to the new one without manual intervention. On the HashiCorp Terraform Associate TF-003 exam, this scenario tests your understanding of state management and the backend migration workflow, often appearing as a trap where candidates mistakenly think they must manually move the state file or delete the old state first. A common pitfall is assuming terraform apply is required, but init handles the entire migration. Remember the mnemonic: “Update and Init to Migrate State”—you change the config, then let init do the heavy lifting.

⚠ Common exam trap

A common misconception is that manually copying the state file is required or that `terraform plan` can validate backend changes, when in fact the correct workflow is to update the backend block and run `terraform init -reconfigure` to reinitialize the 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

Run `terraform init -reconfigure` to update the backend configuration.

`terraform init -reconfigure` forces Terraform to reinitialize the backend and apply the new backend configuration from the `backend` block without prompting for confirmation. Option E is correct because the `backend` block in the Terraform configuration must be updated to reference the new S3 bucket name; Terraform reads this block during initialization to determine where to store and retrieve state. Together, these steps ensure Terraform knows the new backend location and can properly manage state going forward.

Answer analysis

Option-by-option breakdown

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

  • Run `terraform plan` to verify no resource changes before migration.

    Why it's wrong here

    Good practice but not a necessary step for migration.

  • Delete the old state file after migration.

    Why it's wrong here

    Not recommended; Terraform manages old state file retention.

  • Run `terraform init -reconfigure` to update the backend configuration.

    Why this is correct

    This command initializes the new backend and copies state.

  • Manually copy the state file from the old bucket to the new bucket.

    Why it's wrong here

    `init` handles the copy; manual copy is error-prone.

  • Update the `backend` block in the Terraform configuration with the new bucket name.

    Why this is correct

    This is required to point to the new backend.

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

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 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?

hard
  • A.Execute `terraform init` and confirm yes when prompted to copy existing state
  • B.Run `terraform state push` to upload the local state
  • C.Delete the local state file and run `terraform apply` to recreate
  • D.Manually copy the state file to S3 using AWS CLI

Why A: 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.

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.