nerdexam
HashiCorp

TA-002-P · Question #408

How would you reference the Volume IDs associated with the ebs_block_device blocks in this configuration?

The correct answer is A. aws_instance.example.ebs_block_device.[*].volume_id. Because ebs_block_device is a block that can appear multiple times in a single aws_instance resource, it forms a set of objects. To retrieve an attribute across all instances of a repeated block, you use a splat expression with []…

Read, generate, and modify configuration

Question

How would you reference the Volume IDs associated with the ebs_block_device blocks in this configuration?

Exhibit

TA-002-P question #408 exhibit

Options

  • Aaws_instance.example.ebs_block_device.[*].volume_id
  • Baws_instance.example.ebs_block_device.volume_id
  • Caws_instance.example.ebs_block_device[sda2,sda3].volume_id
  • Daws_instance.example.ebs_block_device.*.volume_id

How the community answered

(28 responses)
  • A
    79% (22)
  • B
    4% (1)
  • C
    14% (4)
  • D
    4% (1)

Explanation

Because ebs_block_device is a block that can appear multiple times in a single aws_instance resource, it forms a set of objects. To retrieve an attribute across all instances of a repeated block, you use a splat expression with [*]: aws_instance.example.ebs_block_device.[*].volume_id. This returns a list of all volume IDs from all ebs_block_device blocks. The legacy splat syntax .* also works but [*] is the modern, preferred form. Options B and C are syntactically invalid for this use case. Answer A is correct.

Topics

#Terraform HCL Syntax#Referencing Attributes#Splat Operator#Nested Blocks

Community Discussion

No community discussion yet for this question.

Full TA-002-P Practice