If you want to replace a VM created by Terraform with an identical one without affecting a database, which approach is best?

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

If you want to replace a VM created by Terraform with an identical one without affecting a database, which approach is best?

Explanation:
Marking a resource as tainted signals Terraform to recreate that resource on the next apply. By tainting the VM, you tell Terraform that the existing instance is unhealthy and must be replaced. The ensuing plan will show a destroy and recreate for that VM, while leaving the database resource untouched because it’s a separate resource with its own lifecycle. When you apply, Terraform performs only the VM replacement, producing an identical new VM and preserving the database intact. This approach is the safe and direct way to replace a single resource without disturbing other infrastructure.

Marking a resource as tainted signals Terraform to recreate that resource on the next apply. By tainting the VM, you tell Terraform that the existing instance is unhealthy and must be replaced. The ensuing plan will show a destroy and recreate for that VM, while leaving the database resource untouched because it’s a separate resource with its own lifecycle. When you apply, Terraform performs only the VM replacement, producing an identical new VM and preserving the database intact. This approach is the safe and direct way to replace a single resource without disturbing other infrastructure.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy