Exam Terraform Associate All QuestionsBrowse all questions from this exam
Question 324

Why would you use the -replace flag for terraform apply?

    Correct Answer: C

    You want to force Terraform to destroy and recreate a resource on the next apply. The -replace flag is used to instruct Terraform to plan a replacement for a specified resource, forcing it to be destroyed and recreated during the next apply command. This is useful when a resource has become degraded or when you need to refresh it entirely.

Discussion
SilentHOption: C

C is the answer. The full syntax is "terraform apply -replace=[ADDRESS]" Instructs Terraform to plan to replace the resource instance with the given address. This is helpful when one or more remote objects have become degraded, and you can use replacement objects with the same configuration to align with immutable infrastructure patterns. You cannot use -replace with the -destroy option, and it is only available from Terraform v0.15.2 onwards. For earlier versions, use terraform taint to achieve a similar result. https://developer.hashicorp.com/terraform/cli/commands/plan#planning-options