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?✗ Incorrect
The length function counts the number of items in the list, which is 3.
What is the result of
flatten([["x"], ["y", "z"]])?✗ Incorrect
Flatten removes one level of nesting, combining all inner lists into one list.
What does
merge({a=1, b=2}, {b=3, c=4}) return?✗ Incorrect
The second map's value for key 'b' (3) overwrites the first map's value (2).
Which function would you use to count items in a list?
✗ Incorrect
length() counts the number of items in a collection.
If you have a list of lists, which function helps you make it a single list?
✗ Incorrect
flatten() combines nested lists into one flat list.
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.