Question 350
A Terraform associate evaluates: A loop must access elements by stable string keys instead of relying on arbitrary set order. Select TWO complementary responses: the appropriate action AND direct evidence it worked.
Explanation
Correct Answers
The case says: A loop must access elements by stable string keys instead of relying on arbitrary set order. The directly relevant Terraform response is: Select list when element order and duplicates matter, set for unique unordered values, and map for values indexed by string keys. This addresses the related failure mode: Using a set where stable indices are required can make addressing and ordering assumptions invalid. Validate the result by checking: A small console evaluation verifies indexing and keys match the intended collection semantics. The selection matches this objective, rather than a different Terraform administration task.
The observed situation is: A loop must access elements by stable string keys instead of relying on arbitrary set order. The acceptance evidence is: A small console evaluation verifies indexing and keys match the intended collection semantics. It verifies the corrective approach (Select list when element order and duplicates matter, set for unique unordered values, and map for values indexed by string keys.) and controls the risk: Using a set where stable indices are required can make addressing and ordering assumptions invalid. Checking an unrelated Terraform setting would not prove the stated requirement was met.
Incorrect Answers
Terraform may not infer relationships that have no data reference, but excessive explicit dependencies can make plans unnecessarily conservative. This belongs to Explicit depends_on for hidden dependencies (official objective 4f). Its separate risk is that terraform may not infer relationships that have no data reference, but excessive explicit dependencies can make plans unnecessarily conservative. The question instead tests Terraform list set and map collections; that other safeguard alone does not verify it.
A root-level consumer resolves a declared module output and no undeclared child address is referenced. That addresses Cross-module output references (official objective 4b), specifically the hazard that trying to reach directly into a child module's private resource address bypasses the module interface. Here the necessary action or evidence is the paired action Select list when element order and duplicates matter, set for unique unordered values, and map for values indexed by string keys and separate validation A small console evaluation verifies indexing and keys match the intended collection semantics, not that separate control.
Use object type constraints for named fields and tuple for fixed-position heterogeneous elements when modeling structured input variables. This addresses Object and tuple structural types (official objective 4d). The separate hazard is that treating a structured object like an untyped string makes required fields and attribute access error-prone. It does not by itself satisfy the case-specific requirement for Terraform list set and map collections.