Terraform Associate 004 ยท Core Terraform workflow
Plan options: target, replace, refresh-only, destroy
-target, -replace=ADDRESS (replacing taint), -refresh-only, -destroy, -var and -var-file on plan, when each is appropriate (3d).
Key points
- target=ADDRESS limits the plan to the matching resource and its dependencies; it is meant for exceptional cases, not routine use. -replace=ADDRESS forces re-creation of one instance (the modern alternative to taint) and cannot be combined with -destroy. -refresh-only only updates state and outputs to match changes made outside Terraform. -destroy previews removing everything. -var and -var-file supply input variables.
Source: https://developer.hashicorp.com/terraform/cli/commands/plan
Practice questions
Which plan option forces one resource instance to be recreated?
- -replace=ADDRESS
- -refresh-only
- -var-file=FILE
- -detailed-exitcode
Show answer
Answer: A. -replace=ADDRESS
-replace=ADDRESS plans replacement of the given instance. The others record external changes, load variables, or alter the exit code.
Which statements about -target are correct?
- It should be the default way to run every plan
- It limits planning to the resource instance and its dependencies
- It permanently excludes other resources from the configuration
- It tells Terraform to ignore the state file
- It is intended for exceptional cases such as recovering from mistakes
Show answer
Answer: B. It limits planning to the resource instance and its dependencies, E. It is intended for exceptional cases such as recovering from mistakes
-target narrows a run to the chosen resource and what it depends on, and is meant for exceptions. It excludes nothing permanently and does not bypass state.
-replace can be combined with -destroy in the same plan.
Show answer
Answer: False
False. -replace cannot be used with -destroy, since destroy mode already removes every object.
Practice 8 questions on this topic in Bitzu
Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.
