True or False: You can reference a resource created with for_each using a Splat (*) expression.

Prepare for the HashiCorp Terraform Associate Exam with quizzes, flashcards, and multiple-choice questions. Each question includes hints and explanations. Boost your confidence and ace your exam!

Multiple Choice

True or False: You can reference a resource created with for_each using a Splat (*) expression.

Explanation:
Splat expressions pull data from all instances only when the resource was created with count. When you use for_each, Terraform stores instances as a map keyed by your chosen identifiers, so there isn’t a single wildcard that returns all attributes at once. To reference all instances created with for_each, you need a for expression to iterate over the map, or you can access a specific instance by its key. For example, you can build a list of IDs with a for expression like [for inst in aws_instance.web : inst.id], or [for key, inst in aws_instance.web : inst.id]. To get a single instance’s id, reference it by its key such as aws_instance.web["web1"].id. Therefore, the statement is false.

Splat expressions pull data from all instances only when the resource was created with count. When you use for_each, Terraform stores instances as a map keyed by your chosen identifiers, so there isn’t a single wildcard that returns all attributes at once. To reference all instances created with for_each, you need a for expression to iterate over the map, or you can access a specific instance by its key. For example, you can build a list of IDs with a for expression like [for inst in aws_instance.web : inst.id], or [for key, inst in aws_instance.web : inst.id]. To get a single instance’s id, reference it by its key such as aws_instance.web["web1"].id. Therefore, the statement is false.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy