0
0
Terraformcloud~5 mins

Splat expressions in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a splat expression in Terraform?
A splat expression lets you get a list of values from multiple resources or attributes easily, like collecting all names from a group of servers.
Click to reveal answer
beginner
How does the syntax resource_type.resource_name[*].attribute work in Terraform?
It collects the attribute from all instances of resource_name and returns a list of those values.
Click to reveal answer
beginner
Why use splat expressions instead of accessing each resource attribute individually?
Splat expressions save time and code by automatically gathering values from many resources without writing repetitive code.
Click to reveal answer
intermediate
What is the difference between resource[*].attribute and resource.attribute in Terraform?
resource[*].attribute returns a list of attributes from all resources, while resource.attribute accesses a single resource's attribute.
Click to reveal answer
intermediate
Can splat expressions be used with nested attributes in Terraform? Give an example.
Yes, for example aws_instance.example[*].tags["Name"] collects the 'Name' tag from all instances.
Click to reveal answer
What does the splat expression aws_instance.web[*].id return?
AA list of IDs for all aws_instance.web resources
BThe ID of the first aws_instance.web resource
CA single string with all IDs concatenated
DAn error because splat expressions are invalid
Which symbol is used in Terraform splat expressions to select all instances?
A*
B#
C@
D&
If you want to get a list of all public IPs from multiple instances, which expression is correct?
Aaws_instance.example.public_ip
Baws_instance.example[*].public_ip
Caws_instance.example[0].public_ip
Daws_instance.example.public_ip[*]
What type of value does a splat expression return in Terraform?
AMap
BString
CBoolean
DList
Can splat expressions be used with resources created using count or for_each?
AOnly with for_each, not with count
BNo, splat expressions only work with single resources
CYes, they work well to gather attributes from all instances
DOnly with count, not with for_each
Explain what a splat expression is in Terraform and how it helps when working with multiple resources.
Think about how you would get the same attribute from many servers without writing code for each one.
You got /4 concepts.
    Describe the syntax of a splat expression and give an example of how to get all instance IDs from a resource.
    Use the * symbol inside square brackets to select all instances.
    You got /3 concepts.