Question 480
At Oakcrest Logistics Networks, an authorized infrastructure engineering team manages a Terraform 1.12 and HCP Terraform environment. The team encounters the following situation: a module defines for_each instances from a map but another block references an arbitrary numeric index. 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
Keep stable logical instance keys for for_each resources. This control addresses resource addresses with for_each key because for_each instances are addressed by keys whereas count instances use integer indices. The original implementation remedy remains: Refer to the instance using its stable string map key.
Incorrect Answers
This safeguard is for the dependency described by: Resource attributes provide typed dependency links across managed resources. The continuing risk here is determined by: for_each instances are addressed by keys whereas count instances use integer indices. The targeted safeguard is “Keep stable logical instance keys for for_each resources”.
“Publish structured input schemas for reusable modules” addresses a different recurring failure: Terraform object types define explicit named attributes and their expected types. For the condition in this question, maintain “Keep stable logical instance keys for for_each resources” because for_each instances are addressed by keys whereas count instances use integer indices.
That review protects the control associated with: A state lock protects against concurrent state writers that could corrupt mappings. It does not directly prevent the stated recurrence, which concerns: for_each instances are addressed by keys whereas count instances use integer indices. The appropriate guardrail is “Keep stable logical instance keys for for_each resources”.