TA-002-P · Question #433
Once a new Terraform backend is configured with a Terraform code block, which command(s) is (are) used to migrate the state file?
The correct answer is D. terraform init. After configuring a new backend in a Terraform code block, terraform init is the command used to initialize the backend and migrate the local state file to the newly configured remote location.
Question
Once a new Terraform backend is configured with a Terraform code block, which command(s) is (are) used to migrate the state file?
Options
- Aterraform apply
- Bterraform push
- Cterraform destroy, then terraform apply
- Dterraform init
How the community answered
(42 responses)- A2% (1)
- B7% (3)
- C2% (1)
- D88% (37)
Why each option
After configuring a new backend in a Terraform code block, `terraform init` is the command used to initialize the backend and migrate the local state file to the newly configured remote location.
terraform apply is used to create or modify infrastructure and does not handle backend initialization or state file migration between backends.
terraform push is not a standard Terraform CLI command used for migrating state files between backends; this command does not exist in the official CLI.
terraform destroy removes infrastructure, and terraform apply provisions it; neither command is used for the specific task of migrating the state file to a new backend configuration.
When a backend configuration is changed or first set up in Terraform, `terraform init` is the specific command responsible for initializing the backend and migrating the existing local state file to the newly defined remote backend.
Concept tested: Terraform backend initialization and state migration
Source: https://developer.hashicorp.com/terraform/language/settings/backends/configuration#migrating-state
Topics
Community Discussion
No community discussion yet for this question.