nerdexam
HashiCorp

TERRAFORM-ASSOCIATE-004 · Question #70

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 achiev

The correct answer is B. Use the terraform taint command targeting the VMs then run terraform plan and terraform apply. The terraform taint <resource_address> command marks a specific resource for replacement in the next apply. When you subsequently run terraform plan and terraform apply, Terraform will destroy and recreate only that tainted resource (the VM), leaving all other resources (like the

Submitted by dimitri_ru· Apr 18, 2026Use Terraform CLI

Question

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?

Options

  • 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
  • CUse the terraform apply command targeting the VM resources only
  • DDelete the Terraform VM resources from your Terraform code then run terraform plan and

How the community answered

(41 responses)
  • A
    2% (1)
  • B
    80% (33)
  • C
    5% (2)
  • D
    12% (5)

Explanation

The terraform taint <resource_address> command marks a specific resource for replacement in the next apply. When you subsequently run terraform plan and terraform apply, Terraform will destroy and recreate only that tainted resource (the VM), leaving all other resources (like the database) untouched. Note: In Terraform 0.15.2+, the preferred approach is terraform apply -replace=<resource_address>, which combines the taint and apply steps. However, terraform taint remains the answer referenced in this question context.

Topics

#Terraform CLI#Resource replacement#State manipulation#terraform taint

Community Discussion

No community discussion yet for this question.

Full TERRAFORM-ASSOCIATE-004 Practice