To return all the IDs of attached EBS volumes for an AWS virtual machine, which expression should be used?

Master the HashiCorp Terraform Test with these flashcards and multiple choice questions. Each question includes hints and explanations to prepare you effectively. Set yourself up for success!

The chosen answer is correct because it accurately utilizes the syntax of Terraform's interpolation and indexing capabilities to extract the IDs of all attached EBS volumes for an AWS instance resource.

In Terraform, when you're dealing with a resource that has multiple items (like EBS volumes attached to an EC2 instance), you need to use the correct syntax to access those individual items. In this case, aws_instance.example.ebs_block_device refers to a collection of EBS block devices associated with the instance, and the [*] notation is used to denote that we want to operate on all elements within that collection.

The expression aws_instance.example.ebs_block_device[*].id effectively tells Terraform to take the list of EBS block devices and return the id attribute for each of them, resulting in a list of all the IDs of the attached EBS volumes.

This approach respects the structure of the Terraform resource data, ensuring that you can correctly access and manipulate lists of items. The other choices do not correctly follow Terraform's syntax for the desired output, either by misusing indexing or incorrectly referencing attributes. For example, one option inappropriately uses the all keyword, which is not applicable in this context. Another fails to effectively

Subscribe

Get the latest from Examzify

You can unsubscribe at any time. Read our privacy policy