Preparing Practice Exam…
Please wait a moment while the system generates the exam questions, answers, and study session.
Please wait a moment while the system generates the exam questions, answers, and study session.
Question 6 of 112
Free Preview · 112 of 371 · questions 1–112 of 371 are free. Sign up free to sync your progress across devices.
Select one answer.
Written by other learners. Comments can disagree with the marked answer — check the official documentation when in doubt.
According to official Terraform documentation, you cannot reference a resource created with for_each using a splat ([*]) expression directly.
It was a brain-buster, but I finally figured it out: you can’t use the splat operator to access the entire resource object.
resource "aws_instance" "example" { for_each = { "vm1" = "t2.micro" "vm2" = "t2.small" } ami = "ami-123456" instance_type = each.value } output "instance_ids" { value = aws_instance.example[*].id } for_each creates two instances: vm1 and vm2. The expression aws_instance.example[*].id is a splat expression that collects the id of each instance into a list. The result is a list of instance IDs.