vm_names with three VM names: "vm1", "vm2", "vm3"aws_instance resources using a for_each loop over vm_namespublic_ip attribute set to a unique IP stringpublic_ips containing all public IPs from the instancesvm_names with three VM names: "vm1", "vm2", "vm3"aws_instance resources using a for_each loop over vm_namespublic_ip attribute set to a unique IP stringpublic_ips containing all public IPs from the instancesvm_names as a list with these exact values: "vm1", "vm2", "vm3".Use variable "vm_names" with type = list(string) and set default to the list of names.
aws_instance resources named example using for_each over var.vm_names. Set the public_ip attribute to "10.0.0.${index(toset(var.vm_names), each.key) + 1}" for each instance.Use for_each = toset(var.vm_names) and set public_ip using the index of each key plus 1.
public_ips that uses a splat expression to collect all public_ip values from aws_instance.example resources.Use locals block and assign public_ips = aws_instance.example[*].public_ip.
output block named all_public_ips that outputs the local variable public_ips.Use output "all_public_ips" block with value = local.public_ips.
What does a splat expression in Terraform do?
Example: aws_instance.example[*].id
** means 'all items' in the list of resources.aws_instance.example[*].id collects the id attribute from every instance in aws_instance.example.id attribute from all aws_instance.example resources into a list -> Option AWhich of the following is the correct syntax for a splat expression to get all name attributes from a resource list aws_s3_bucket.buckets?
* must come immediately after the resource list name inside square brackets.resource_list[*].attribute, so aws_s3_bucket.buckets[*].name is correct.Given the Terraform code snippet:
resource "aws_instance" "web" {
count = 3
ami = "ami-123456"
instance_type = "t2.micro"
}
output "instance_ids" {
value = aws_instance.web[*].id
}What will be the output of instance_ids after deployment?
count = 3 creates 3 instances named aws_instance.web[0], aws_instance.web[1], and aws_instance.web[2].aws_instance.web[*].id collects the id attribute from all 3 instances into a list.Identify the error in this Terraform snippet using splat expressions:
output "bucket_names" {
value = aws_s3_bucket.buckets.name[*]
}* must be inside brackets immediately after the resource list, not after the attribute.aws_s3_bucket.buckets[*].name, not aws_s3_bucket.buckets.name[*].* is incorrectly placed after the attribute name -> Option DYou have a list of AWS EC2 instances created with count = 4. You want to output a list of their public IPs but only for instances that have a tag Environment set to production. Which Terraform expression correctly uses splat and filtering?
aws_instance.web[*].public_ip collects all public IPs, no filtering.[for i in aws_instance.web : i.public_ip if i.tags.Environment == "production"].Pass the test and this pattern moves unknown