HashiCorp Certified: Terraform Associate free question 5 / 10 · Domain 4: Terraform configuration
An engineer changes an argument of a resource, and the remote API cannot update that argument on an existing object. What does the resources overview say Terraform does when the change is applied?
- It updates the object in place, and the API ignores the argument.
- It stops, because the object must first be removed from the state.
- It destroys the object and re-creates it with the new arguments.
- It keeps the object and records only the new argument in the state.
Show the answer and explanation
Answer: C
Why this is correct
The resources overview lists what Terraform does when you apply a configuration. It creates resources that do not yet exist as real infrastructure objects. It destroys resources that exist in the state but no longer exist in the configuration. It updates resources in place if their arguments have changed. It destroys and re-creates resources whose arguments have changed but cannot be updated in-place due to remote API limitations. Finally, it updates the state file so that the configuration, the real infrastructure, and the state match. Whether an argument can be updated in place is decided by the remote API, so the same kind of edit can produce an update for one argument and a replacement for another.
Why the other options are wrong
"It updates the object in place, and the API ignores the argument." … Updating in place is what apply does when an argument can be updated. The overview lists a separate operation for arguments that cannot be updated in-place because of remote API limitations.
"It keeps the object and records only the new argument in the state." … Apply updates the state file so that the configuration, the real infrastructure, and the state match. Recording a value the real object does not have would leave them out of step.
"It stops, because the object must first be removed from the state." … Removing a resource from state is a separate task that keeps the real object without Terraform managing it. Apply handles this change itself by destroying and re-creating the object.
Update in place, or replace
Changed arguments are updated in place when the API allows it. When it does not, apply destroys and re-creates the object, and the plan shows that replacement.