HashiCorp Certified: Terraform Associate — Question 328
You've used Terraform to deploy a virtual machine and a database. You want to replace this virtual machine instance with an identical one without affecting the database. What is the best way to achieve this using Terraform?
Answer options
- A. Use the terraform state rm command to remove the VM from state file
- B. Use the terraform taint command targeting the VMs then run terraform plan and terraform apply
- C. Use the terraform apply command targeting the VM resources only
- D. Delete the Terraform VM resources from your Terraform code then run terraform plan and terraform apply
Correct answer: B
Explanation
The correct answer is B because using the terraform taint command marks the existing VM as needing replacement, and running terraform plan and apply will create a new instance while preserving the database. Option A incorrectly removes the VM from the state file without creating a replacement. Option C only applies changes to the VM resources without ensuring the old instance is properly replaced. Option D would delete the VM resources from code, which is not the desired approach for replacement.