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.
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)- A3% (1)
- B89% (32)
- C6% (2)
- D3% (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.
`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.
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.
`terraform refresh` updates the state file to reflect the real-world infrastructure but does not migrate the state file to a different backend.
`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
Community Discussion
No community discussion yet for this question.