Welcome to ExamTopics
ExamTopics Logo
- Expert Verified, Online, Free.
exam questions

Exam Terraform Associate All Questions

View all questions & answers for the Terraform Associate exam

Exam Terraform Associate topic 1 question 109 discussion

Actual exam question from HashiCorp's Terraform Associate
Question #: 109
Topic #: 1
[All Terraform Associate Questions]

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

  • A. aws_instance.example.ebs_block_device.[*].volume_id
  • B. aws_instance.example.ebs_block_device.volume_id
  • C. aws_instance.example.ebs_block_device[sda2,sda3].volume_id
  • D. aws_instance.example.ebs_block_device.*.volume_id
Show Suggested Answer Hide Answer
Suggested Answer: D 🗳️

Comments

Chosen Answer:
This is a voting comment (?) , you can switch to a simple comment.
Switch to a voting comment New
KJ_Rollings
Highly Voted 1 year, 6 months ago
Selected Answer: D
It's D. If you're using square brackets, then it should be like, ebs_block_device[*].volume_id
upvoted 18 times
...
fedeX
Highly Voted 1 year, 10 months ago
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.
upvoted 18 times
...
kennywuu
Most Recent 10 months, 3 weeks ago
it is D. Just check it in terraform console, only D is passed :)
upvoted 4 times
...
TigerInTheCloud
11 months, 1 week ago
Selected Answer: D
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 }
upvoted 1 times
TigerInTheCloud
11 months, 1 week ago
C can rewrite as: [for v in ["sda2", "sda3"] : aws_instance.example.ebs_block_device[v].volume_id]
upvoted 1 times
...
...
Tyler2023
1 year ago
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.
upvoted 3 times
...
MauroSoli
1 year, 1 month ago
The answer is D but it's a form deprecated
upvoted 1 times
...
amehim
1 year, 1 month ago
I with D: > aws_instance.app_server.ebs_block_device.*.volume_id tolist([ "vol-0aa30805cf71780e4", "vol-081f89b26f2fed5ac", ])
upvoted 1 times
...
vj_dhaksh
1 year, 5 months ago
answer is D.. <<<Tested >>>
upvoted 4 times
...
Nunyabiznes
1 year, 8 months ago
Selected Answer: D
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.
upvoted 4 times
...
lordoftheringsnewavatar
1 year, 8 months ago
output "splat" { value = aws_instance.test-vm.ebs_block_device.*.volume_id } Outputs: splat = tolist([ "vol-088ecdfa25d46bb49", "vol-030bfe9d14a06ecd2", ]) Selected Answer: D
upvoted 1 times
...
alexsandroe
1 year, 9 months ago
Selected Answer: D
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}"] }
upvoted 2 times
...
awsguys
1 year, 9 months ago
D => Right
upvoted 2 times
...
gekkehenk
1 year, 10 months ago
Selected Answer: D
The brackets do not work, asterisk only.
upvoted 4 times
...
resnef
1 year, 10 months ago
Selected Answer: D
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. ╵
upvoted 3 times
...
AB7088
1 year, 11 months ago
If remove the dot then the answer should be A. I think there has a typo.. D is not correct.
upvoted 2 times
...
BaburTurk
1 year, 11 months ago
aws_instance.example.ebs_block_device[*].volume_id or aws_instance.example.ebs_block_device.*.volume_id then D is the answer
upvoted 2 times
...
secdaddy
1 year, 11 months ago
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
upvoted 2 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...