The count = 3 creates 3 instances named aws_instance.web[0], aws_instance.web[1], and aws_instance.web[2].
Step 2: Splat expression collects all instance IDs
The expression aws_instance.web[*].id collects the id attribute from all 3 instances into a list.
Final Answer:
A list of 3 instance IDs, one for each created instance -> Option B
Quick Check:
count 3 + splat = list of 3 IDs [OK]
Hint: count creates multiple; splat collects all attributes [OK]
Common Mistakes:
Thinking splat fails with count
Expecting single ID instead of list
Assuming no instances created
4.
Identify the error in this Terraform snippet using splat expressions:
output "bucket_names" {
value = aws_s3_bucket.buckets.name[*]
}
medium
A. Output blocks cannot use splat expressions
B. The resource name aws_s3_bucket.buckets is invalid
C. Missing quotes around the attribute name
D. The splat operator * is incorrectly placed after the attribute name
Solution
Step 1: Check splat operator position
The splat operator * must be inside brackets immediately after the resource list, not after the attribute.
Step 2: Correct syntax
The correct syntax is aws_s3_bucket.buckets[*].name, not aws_s3_bucket.buckets.name[*].
Final Answer:
The splat operator * is incorrectly placed after the attribute name -> Option D
Quick Check:
Splat must be after resource list, not attribute [OK]
Hint: Put * right after resource list in brackets, not after attribute [OK]
Common Mistakes:
Placing * after attribute name
Confusing resource and attribute order
Thinking output blocks disallow splat
5.
You 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?
hard
A. aws_instance.web[*].public_ip
B. aws_instance.web[*].tags.Environment == "production" ? aws_instance.web[*].public_ip : []
C. [for i in aws_instance.web : i.public_ip if i.tags.Environment == "production"]
D. aws_instance.web[?tags.Environment=="production"].public_ip
Solution
Step 1: Understand splat collects all attributes without filtering
The expression aws_instance.web[*].public_ip collects all public IPs, no filtering.
Step 2: Use for-expression with condition for filtering
The correct way to filter is using a for-expression with an if condition: [for i in aws_instance.web : i.public_ip if i.tags.Environment == "production"].
Final Answer:
[for i in aws_instance.web : i.public_ip if i.tags.Environment == "production"] -> Option C
Quick Check:
Filter with for-expression + if, not splat alone [OK]
Hint: Use for-expression with if to filter, splat alone can't filter [OK]
Common Mistakes:
Using splat without filtering
Trying to filter inside splat syntax
Using invalid filter syntax
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.