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.
Reference:
Terraform Splat Expressions: https://www.terraform.io/docs/language/expressions/splat.html
Explains the .*. operator for accessing all elements of a list.
AWS Provider aws_instance Documentation: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/instance#ebs_block_device
Confirms that ebs_block_device is a list of blocks, and attributes like volume_id are accessible.
Final Answer:
D. aws_instance.example.ebs_block_device.*.volume_id is the correct option to reference the volume IDs for all ebs_block_device blocks in the configuration.
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
}
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.
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.
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.
╵
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.
KJ_Rollings
Highly Voted 1Â year, 7Â months agofedeX
Highly Voted 1Â year, 11Â months agovl67
Most Recent 1Â month agokennywuu
11Â months, 3Â weeks agoTigerInTheCloud
1Â year agoTigerInTheCloud
1Â year agoTyler2023
1Â year, 1Â month agoMauroSoli
1Â year, 1Â month agoamehim
1Â year, 2Â months agovj_dhaksh
1Â year, 6Â months agoNunyabiznes
1Â year, 8Â months agolordoftheringsnewavatar
1Â year, 8Â months agoalexsandroe
1Â year, 9Â months agoawsguys
1Â year, 10Â months agogekkehenk
1Â year, 11Â months agoresnef
1Â year, 11Â months agoAB7088
2Â years agoBaburTurk
2Â years ago