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

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.