nerdexam
HashiCorp

TA-002-P · Question #366

You decide to move a Terraform state file to Amazon S3 from another location. You write the code below into a file called\ You immediately run terraform apply but don't see any changes. Your state…

The correct answer is B. terraform init. To migrate a Terraform state file to a newly configured remote backend, you must run terraform init, which detects the backend change and prompts to migrate the state.

Use the Terraform CLI (terraform plan, apply, destroy, fmt, init, validate, workspace, import, taint, providers, output)

Question

You decide to move a Terraform state file to Amazon S3 from another location. You write the code below into a file called\ You immediately run terraform apply but don't see any changes. Your state file didn't move. Which command will migrate your current state file to the new S3 remote backend?

Options

  • Aterraform push
  • Bterraform init
  • Cterraform refresh
  • Dterraform state

How the community answered

(36 responses)
  • A
    3% (1)
  • B
    89% (32)
  • C
    6% (2)
  • D
    3% (1)

Why each option

To migrate a Terraform state file to a newly configured remote backend, you must run `terraform init`, which detects the backend change and prompts to migrate the state.

Aterraform push

`terraform push` is not a standard Terraform command for state migration; it's sometimes used in specific enterprise contexts but not for general backend migration.

Bterraform initCorrect

When you modify the backend configuration in your Terraform code (e.g., from local to S3), running `terraform init` is the command that detects this change. It will prompt you to migrate your existing local state file to the newly configured remote backend, effectively moving the state.

Cterraform refresh

`terraform refresh` updates the state file to reflect the real-world infrastructure but does not migrate the state file to a different backend.

Dterraform state

`terraform state` is a command used to inspect and manipulate the state file, but it does not automatically migrate the state file to a new backend configuration.

Concept tested: Terraform backend migration with init

Source: https://developer.hashicorp.com/terraform/cli/commands/init

Topics

#Terraform state management#Terraform backends#terraform init#State migration

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice