Question 840
A Terraform rollout has two separate requirements: first, protect a declared resource from plans that destroy its managed object; second, replace a resource when a specified managed resource change occurs. Which assignment of mechanisms correctly handles both responsibilities?
Explanation
Correct Answer
The first requirement, to protect a declared resource from plans that destroy its managed object, is handled by prevent_destroy lifecycle: prevent_destroy causes an error if a plan includes destruction while the rule is present in configuration. The second requirement, to replace a resource when a specified managed resource change occurs, is handled by replace_triggered_by lifecycle: replace_triggered_by adds replacement behavior tied to changes in other managed objects or attributes. Each of these mechanisms has a distinct responsibility.
Incorrect Answers
For the requested tasks to protect a declared resource from plans that destroy its managed object and replace a resource when a specified managed resource change occurs, the first candidate replace_triggered_by lifecycle addresses replace a resource when a specified managed resource change occurs; the second candidate prevent_destroy lifecycle addresses protect a declared resource from plans that destroy its managed object. This mapping fails because the first mechanism primarily supports the task to replace a resource when a specified managed resource change occurs and the second mechanism primarily supports the task to protect a declared resource from plans that destroy its managed object; the actual requirements are protect a declared resource from plans that destroy its managed object first and replace a resource when a specified managed resource change occurs second.
For the requested tasks to protect a declared resource from plans that destroy its managed object and replace a resource when a specified managed resource change occurs, the first candidate prevent_destroy lifecycle addresses protect a declared resource from plans that destroy its managed object; the second candidate Terraform resource graph cycle addresses detect an impossible dependency ordering caused by circular references. This mapping fails because the second mechanism primarily supports the task to detect an impossible dependency ordering caused by circular references; the actual requirements are protect a declared resource from plans that destroy its managed object first and replace a resource when a specified managed resource change occurs second.
For the requested tasks to protect a declared resource from plans that destroy its managed object and replace a resource when a specified managed resource change occurs, the first candidate Terraform resource graph cycle addresses detect an impossible dependency ordering caused by circular references; the second candidate Implicit dependency from expression addresses order resources when one consumes an attribute produced by another. This mapping fails because the first mechanism primarily supports the task to detect an impossible dependency ordering caused by circular references and the second mechanism primarily supports the task to order resources when one consumes an attribute produced by another; the actual requirements are protect a declared resource from plans that destroy its managed object first and replace a resource when a specified managed resource change occurs second.
For the requested tasks to protect a declared resource from plans that destroy its managed object and replace a resource when a specified managed resource change occurs, the first candidate Implicit dependency from expression addresses order resources when one consumes an attribute produced by another; the second candidate replace_triggered_by lifecycle addresses replace a resource when a specified managed resource change occurs. This mapping fails because the first mechanism primarily supports the task to order resources when one consumes an attribute produced by another; the actual requirements are protect a declared resource from plans that destroy its managed object first and replace a resource when a specified managed resource change occurs second.