How would you reference the Volume IDs associated with the ebs_block_device blocks on an AWS instance named example?

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

How would you reference the Volume IDs associated with the ebs_block_device blocks on an AWS instance named example?

Explanation:
The main idea is using a splat expression to collect attributes from multiple nested blocks inside a resource. An aws_instance can have several ebs_block_device blocks, and to get the volume_id from every one of them, you reference the nested block path with a splat. The correct form is aws_instance.example.ebs_block_device.[*].volume_id because [*] selects all ebs_block_device blocks on that instance, and .volume_id picks the ID from each one. This returns a list of all attached volume IDs. Other forms don’t properly capture all blocks: a bare *.volume_id isn’t the standard way to reference multiple nested blocks, indexing by device names isn’t how Terraform references those blocks, and listing explicit indices would only give you specific blocks rather than everything attached.

The main idea is using a splat expression to collect attributes from multiple nested blocks inside a resource. An aws_instance can have several ebs_block_device blocks, and to get the volume_id from every one of them, you reference the nested block path with a splat. The correct form is aws_instance.example.ebs_block_device.[].volume_id because [] selects all ebs_block_device blocks on that instance, and .volume_id picks the ID from each one. This returns a list of all attached volume IDs.

Other forms don’t properly capture all blocks: a bare *.volume_id isn’t the standard way to reference multiple nested blocks, indexing by device names isn’t how Terraform references those blocks, and listing explicit indices would only give you specific blocks rather than everything attached.

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy