You want to create a string that combines a generated random_id and a variable and reuse that string several times in your configuration. What is the simplest correct way to implement this without repeating the random_id and variable?
Correct Answer: C
* Rationale for Correct answer: A local value (locals { ... }) is the simplest way to define a reusable expression once and reference it many times via local. < name > . This is exactly what locals are for:
reducing repetition and improving readability when combining values like random_id results and variables.
* Analysis of Incorrect Options (Distractors):
* A (Module): Overkill-modules are for packaging reusable groups of resources, not simple string reuse inside the same configuration.
* B (Output value): Outputs are for exposing values to the CLI or to parent modules, not for internal reuse within the same module.
* D (Data source): Data sources read existing remote objects; they are not intended for composing local strings.
* Key Concept: Using locals to avoid repeating expressions.
Reference: Terraform Objectives - Read, Generate, and Modify Configurations (locals, expressions, and reuse patterns).