0
0
Terraformcloud~5 mins

Collection functions (length, flatten, merge) in Terraform - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What does the length() function do in Terraform collections?
The length() function returns the number of items in a list, map, or string. It helps you count how many elements are inside a collection.
Click to reveal answer
beginner
How does the flatten() function work in Terraform?
The flatten() function takes a list of lists and combines all inner lists into a single flat list. It removes one level of nesting.
Click to reveal answer
beginner
What is the purpose of the merge() function in Terraform?
The merge() function combines two or more maps into one map. If keys overlap, later maps overwrite earlier ones.
Click to reveal answer
beginner
Example: What is the output of length(["apple", "banana", "cherry"])?
The output is 3 because there are three items in the list.
Click to reveal answer
beginner
Example: What does flatten([[1, 2], [3, 4], [5]]) return?
It returns [1, 2, 3, 4, 5], a single list with all elements from the inner lists combined.
Click to reveal answer
What does length(["a", "b", "c"]) return?
A3
B2
C1
DError
What is the result of flatten([["x"], ["y", "z"]])?
A["x", "y", "z"]
B[["x"], ["y", "z"]]
C["x"]
DError
What does merge({a=1, b=2}, {b=3, c=4}) return?
A{a=1, b=2, c=4}
B{a=1, b=3, c=4}
C{a=1, b=2}
DError
Which function would you use to count items in a list?
Aconcat()
Bmerge()
Cflatten()
Dlength()
If you have a list of lists, which function helps you make it a single list?
Alength()
Bmerge()
Cflatten()
Dsplit()
Explain how the length(), flatten(), and merge() functions work in Terraform collections.
Think about counting, combining lists, and combining maps.
You got /3 concepts.
    Describe a real-life example where you might use flatten() and merge() in Terraform.
    Imagine organizing lists or settings from different sources.
    You got /2 concepts.