Terraform Associate Exam QuestionsBrowse all questions from this exam

Terraform Associate Exam - Question 109


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

Show Answer
Correct Answer: D

To reference the Volume IDs associated with the ebs_block_device blocks in the given AWS instance resource configuration, you should use the splat operator (*). The correct syntax is aws_instance.example.ebs_block_device.*.volume_id, which accesses the volume_id field for each EBS block device attached to the aws_instance resource named example. This will create a list of the volume_id values for each block device.

Discussion

26 comments
Sign in to comment
KJ_RollingsOption: D
Nov 18, 2023

It's D. If you're using square brackets, then it should be like, ebs_block_device[*].volume_id

fedeX
Jul 10, 2023

100% D. aws_instance.example.ebs_block_device.*.volume_id and aws_instance.example.ebs_block_device[*].volume_id are equivalent and will both refer to the volume_id field for all of the EBS block devices that are attached to the aws_instance resource with the name example. The * syntax is known as the "splat" operator and can be used to indicate that the preceding attribute should be repeated for each element in a list. It can be used with both the . and [] notation. For example, suppose you have an aws_instance resource named example that has two EBS block devices attached to it, with volume_id values of vol-12345678 and vol-87654321. You could use the * operator like this: aws_instance.example.ebs_block_device.*.volume_id # This will evaluate to ["vol-12345678", "vol-87654321"] aws_instance.example.ebs_block_device[*].volume_id # This will also evaluate to ["vol-12345678", "vol-87654321"] In both cases, the volume_id field is being accessed for each element in the ebs_block_device list, and the resulting value is a list of the volume_id values for each element.

vj_dhaksh
Dec 14, 2023

answer is D.. <<<Tested >>>

zyxphreezOption: A
Mar 2, 2023

What a problem, i just tested both: aws_instance.example.ebs_block_device.[*].volume_id and aws_instance.example.ebs_block_device.*.volume_id and both worked for me... this is the output ids = tolist([ "vol-0a108f108a3f8b14a", "vol-06d606c5904d12c70", ]) i think something is missing within the description... i think we need to choose two...

RVivek
Mar 26, 2023

checked all the values in my lab. D is the only one which worked A has a . befoe [ , if that . is removed then it works

RVivek
Mar 29, 2023

aws_instance.example.ebs_block_device.[*].volume_id does not work unless you remove the . before [

shopkittyOption: A
Mar 8, 2023

Should be A, for further information go to https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/device_naming.html

H4desOption: D
Apr 5, 2023

A is wrong because there is a dot "." in front of the open square brackets "[", if A was aws_instance.example.ebs_block_device[*].volume_id, then it is correct

alifieOption: D
Apr 14, 2023

It is D indeed, for A to work you need to remove the . in front of [*]

gekkehenkOption: D
Jul 11, 2023

The brackets do not work, asterisk only.

NunyabiznesOption: D
Sep 27, 2023

D. aws_instance.example.ebs_block_device.*.volume_id To reference the Volume IDs associated with the ebs_block_device blocks in the given aws_instance resource, you can use the .* syntax to reference all elements of the list. The ebs_block_device blocks are represented as a list in the aws_instance resource, and each block has a volume_id attribute that you can reference.

kennywuu
Jul 2, 2024

it is D. Just check it in terraform console, only D is passed :)

resnefOption: D
Jul 10, 2023

Answer is D > aws_instance.example.ebs_block_device.*.volume_id tolist([ "vol-123457", "vol-43437834743348", ]) > aws_instance.example.ebs_block_device.[*].volume_id ╷ │ Error: Invalid attribute name │ │ on <console-input> line 1: │ (source code not available) │ │ An attribute name is required after a dot. ╵

Tyler2023
May 3, 2024

All of them are invalid expression Based on this https://developer.hashicorp.com/terraform/language/expressions/references The arguments of the ebs_block_device nested blocks can be accessed using a splat expression. For example, to obtain a list of all of the device_name values, use aws_instance.example.ebs_block_device[*].device_name.

yaza
Mar 26, 2023

D. A is wrong because there is a dot before [*]. to be correct it should be aws_instance.example.ebs_block_device[*].volume_id

yaza
Apr 6, 2023

Selected Answer: D

yogishrb2020Option: D
Apr 8, 2023

Tested out in cloud acadmy lab

secdaddy
Jun 6, 2023

resource "aws_instance" "example" { ami = "ami-0f15e0a4c8d3ee5fe" instance_type = "t2.micro" ebs_block_device { device_name = "/dev/sda1" volume_size = "16" } ebs_block_device { device_name = "/dev/sda2" volume_size = "20" } } output "device-list" { value = aws_instance.example.ebs_block_device[*].volume_id } A as written fails. A without the period after device works │ 24: value = aws_instance.example.ebs_block_device.[*].volume_id │ An attribute name is required after a dot. B fails │ 24: value = aws_instance.example.ebs_block_device.volume_id │ Block type "ebs_block_device" is represented by a set of objects, and set elements do not have addressable keys. To find elements matching C fails (even though there is a closing bracket) │ 24: value = aws_instance.example.ebs_block_device[sda2,sda3].volume_id │ The index operator must end with a closing bracket ("]"). D works as written

BaburTurk
Jun 20, 2023

aws_instance.example.ebs_block_device[*].volume_id or aws_instance.example.ebs_block_device.*.volume_id then D is the answer

AB7088
Jun 21, 2023

If remove the dot then the answer should be A. I think there has a typo.. D is not correct.

awsguys
Aug 2, 2023

D => Right

alexsandroeOption: D
Aug 25, 2023

one valid expierience resource "aws_instance" "example" { ami = "ami-a10b4dc2" instance_type = "t2.micro" # Connect the instance to the EBS Volumes attached # https://www.terraform.io/docs/providers/aws/r/instance.html#ebs_block_device ebs_block_device { device_name = "/dev/sda1" volume_size = 10 volume_type = "gp2" } ebs_block_device { device_name = "/dev/sdb1" volume_size = 20 volume_type = "gp2" } } output "splat" { value = ["${aws_instance.example.*.id}", "${aws_ebs_volume.example.*.id}"] }

RVivekOption: D
Mar 26, 2023

checked all the values in my lab. D is the only one which worked A has a . befoe [ , if that . is removed then it works

mixymaster
May 19, 2023

Anyone can explain why is not C? It's fit to the pattern "aws_instance.example.ebs_block_device.[*].volume_id" and have values from the example

alirasouliOption: D
Jun 4, 2023

As discussed, aws_instance.example.ebs_block_device.*.volume_id or aws_instance.example.ebs_block_device[*].volume_id can be right. So here, the only matching choice is D.

lordoftheringsnewavatar
Sep 26, 2023

output "splat" { value = aws_instance.test-vm.ebs_block_device.*.volume_id } Outputs: splat = tolist([ "vol-088ecdfa25d46bb49", "vol-030bfe9d14a06ecd2", ]) Selected Answer: D

amehim
Apr 7, 2024

I with D: > aws_instance.app_server.ebs_block_device.*.volume_id tolist([ "vol-0aa30805cf71780e4", "vol-081f89b26f2fed5ac", ])

MauroSoli
Apr 25, 2024

The answer is D but it's a form deprecated

TigerInTheCloudOption: D
Jun 19, 2024

A is almost right and better and more modern if there is no extra dot You can add an output and validate each of the expressions: output "ebs-volume-ids" { value = aws_instance.example.ebs_block_device["sda2"].volume_id }

TigerInTheCloud
Jun 19, 2024

C can rewrite as: [for v in ["sda2", "sda3"] : aws_instance.example.ebs_block_device[v].volume_id]