TERRAFORM-ASSOCIATE-004 · Question #141
Once you configure a new Terraform backend with a terraform code block, which command(s) should you use to migrate the state file?
The correct answer is A. terraform destroy, then terraform apply. When you configure a new backend in Terraform, running 'terraform init' detects the backend change and prompts you to migrate the existing state to the new backend. It handles the migration safely without destroying infrastructure. Running 'terraform destroy' followed by 'terrafo
Question
Options
- Aterraform destroy, then terraform apply
- Bterraform init
- Cterraform push
- Dterraform apply
How the community answered
(22 responses)- A77% (17)
- B14% (3)
- C5% (1)
- D5% (1)
Explanation
When you configure a new backend in Terraform, running 'terraform init' detects the backend change and prompts you to migrate the existing state to the new backend. It handles the migration safely without destroying infrastructure. Running 'terraform destroy' followed by 'terraform apply' would tear down all existing infrastructure and rebuild it from scratch - this destroys and recreates resources rather than migrating the state file, which is dangerous and incorrect. 'terraform push' is a legacy/deprecated command, and 'terraform apply' alone does not trigger backend migration. The correct answer should be B.
Topics
Community Discussion
No community discussion yet for this question.