0
0
Terraformcloud~20 mins

Collection functions (length, flatten, merge) in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Collection Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the output of length function on a list?
Given the Terraform expression length(["apple", "banana", "cherry"]), what is the output?
Terraform
length(["apple", "banana", "cherry"])
A2
B3
C0
DError
Attempts:
2 left
💡 Hint
Count the number of items inside the list.
query_result
intermediate
2:00remaining
What does flatten do to nested lists?
What is the result of flatten([[1, 2], [3, 4], [5]]) in Terraform?
Terraform
flatten([[1, 2], [3, 4], [5]])
AError
B[[1, 2], [3, 4], [5]]
C[1, 2, 3, 4, 5]
D[1, [2, 3], 4, 5]
Attempts:
2 left
💡 Hint
Flatten removes one level of nested lists.
📝 Syntax
advanced
2:00remaining
Which merge expression correctly combines two maps?
Select the Terraform expression that correctly merges two maps {a = 1, b = 2} and {b = 3, c = 4} with the second map overriding keys from the first.
Amerge({a = 1, b = 2} + {b = 3, c = 4})
Bmerge({a = 1, b = 2}, {b: 3, c: 4})
Cmerge([{a = 1, b = 2}, {b = 3, c = 4}])
Dmerge({a = 1, b = 2}, {b = 3, c = 4})
Attempts:
2 left
💡 Hint
Use merge with two separate map arguments.
optimization
advanced
2:00remaining
Optimizing nested flatten calls
Given a nested list [[[1], [2, 3]], [[4]]], which expression efficiently flattens it into a single list [1, 2, 3, 4]?
Aflatten(flatten([[[1], [2, 3]], [[4]]]))
Bflatten([1, 2, 3, 4])
Cflatten(flatten(flatten([[[1], [2, 3]], [[4]]])))
Dflatten([[[1], [2, 3]], [[4]]])
Attempts:
2 left
💡 Hint
Use flatten twice to remove two levels of nesting.
🧠 Conceptual
expert
2:00remaining
What is the length of a merged map?
If you merge two maps {x = 10, y = 20} and {y = 30, z = 40}, what is the length of the resulting map?
Terraform
length(merge({x = 10, y = 20}, {y = 30, z = 40}))
A3
B4
C2
DError
Attempts:
2 left
💡 Hint
Keys that appear in both maps are overridden, not duplicated.