Question 580
At Silverlake Cloud Operations, an authorized infrastructure engineering team manages a Terraform 1.12 and HCP Terraform environment. The team encounters the following situation: an environment list changes order and a counted resource configuration schedules unnecessary instance replacements. Choose the technically best Terraform Associate 004 practice response to this particular infrastructure case. Which operational control addresses the risk long term?
Explanation
Correct Answer
Prefer stable keyed iteration where resource identity matters. This control addresses for_each keyed resource instances because count addresses depend on numeric indices while for_each tracks stable instance keys. The original implementation remedy remains: Use for_each with stable meaningful keys for repeated objects.
Incorrect Answers
“Choose output collection shapes that match repeated resources” addresses a different recurring failure: A collection-valued resource has multiple instance results rather than one scalar attribute. For the condition in this question, maintain “Prefer stable keyed iteration where resource identity matters” because count addresses depend on numeric indices while for_each tracks stable instance keys.
This safeguard is for the dependency described by: Creating the replacement first may be impossible when both generations require the same immutable name. The continuing risk here is determined by: Count addresses depend on numeric indices while for_each tracks stable instance keys. The targeted safeguard is “Prefer stable keyed iteration where resource identity matters”.
“Maintain centrally reviewed infrastructure modules and version updates” addresses a different recurring failure: Repeated copied configuration can propagate configuration errors across services. For the condition in this question, maintain “Prefer stable keyed iteration where resource identity matters” because count addresses depend on numeric indices while for_each tracks stable instance keys.