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?
- AUse the terraform state rm command to remove the VM from state file
- BUse the terraform taint command targeting the VMs then run terraform plan and terraform apply (correct answer)
- CUse the terraform apply command targeting the VM resources only
- DDelete the Terraform VM resources from your Terraform code then run terraform plan and terraform apply
Reveal answer & explanationHide answer
The correct answer is B. Option B: Use the terraform taint command targeting the VMs then run terraform plan and terraform apply
Explanation
terraform plan compares configuration and state with real infrastructure and previews the proposed changes without applying them. terraform apply executes the dependency-aware changes required to make infrastructure match the configuration.







