nerdexam
HashiCorp

TA-002-P · Question #318

Which statements best describes what the local variable assignment is doing in the following code snippet:

The correct answer is D. Create a list of route table names eliminating duplicates. The local variable assignment is creating a list of route table names and using a function to remove any duplicate entries, resulting in a unique list.

Read, generate, and modify configuration

Question

Which statements best describes what the local variable assignment is doing in the following code snippet:

Options

  • ACreate a distinct list of route table name objects
  • BCreate a map of route table names to subnet names
  • CCreate a map of route table names from a list of subnet names
  • DCreate a list of route table names eliminating duplicates

How the community answered

(32 responses)
  • A
    3% (1)
  • B
    6% (2)
  • C
    3% (1)
  • D
    88% (28)

Why each option

The local variable assignment is creating a list of route table names and using a function to remove any duplicate entries, resulting in a unique list.

ACreate a distinct list of route table name objects

While it creates a distinct list of names, "objects" implies complex structures, whereas it's typically just strings, and the most accurate description focuses on eliminating duplicates from a list.

BCreate a map of route table names to subnet names

The operation describes creating a list of names, not a map, and there's no explicit mapping to subnet names.

CCreate a map of route table names from a list of subnet names

The operation describes creating a list of names, not a map, and the flow is not "from a list of subnet names" to "route table names" in a mapping context.

DCreate a list of route table names eliminating duplicatesCorrect

Assuming the snippet uses a function like `distinct()` or similar on a list of route table names, the operation specifically aims to process an input list and return a new list containing only unique elements. This effectively eliminates any duplicate route table names from the original collection.

Concept tested: Terraform local variables and list manipulation

Source: https://developer.hashicorp.com/terraform/language/functions/distinct

Topics

#locals#for expressions#data structures#unique values

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice