0
0
Terraformcloud~20 mins

Type conversion functions in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Type Conversion Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Understanding Terraform type conversion with tostring()
What is the output of the following Terraform expression?

tostring(12345)
Terraform
tostring(12345)
Anull
B12345
CError: invalid argument type
D"12345"
Attempts:
2 left
💡 Hint
tostring() converts numbers to strings.
Configuration
intermediate
1:30remaining
Using tonumber() with a string in Terraform
What is the result of this Terraform expression?

tonumber("3.14")
Terraform
tonumber("3.14")
A3.14
B"3.14"
CError: cannot convert string to number
Dnull
Attempts:
2 left
💡 Hint
tonumber() converts strings that look like numbers into numbers.
service_behavior
advanced
2:00remaining
Behavior of tolist() with a map in Terraform
What happens when you apply tolist() to this map in Terraform?

tolist({a = 1, b = 2, c = 3})
Terraform
tolist({a = 1, b = 2, c = 3})
A[{"a" = 1}, {"b" = 2}, {"c" = 3}]
B[1, 2, 3]
CError: cannot convert map to list directly
D["a", "b", "c"]
Attempts:
2 left
💡 Hint
tolist() extracts the values from the map in order.
Architecture
advanced
2:00remaining
Converting a list of strings to a set in Terraform
Given this list:

["apple", "banana", "apple", "orange"]

Which Terraform function call produces a set with unique items?
Terraform
["apple", "banana", "apple", "orange"]
Atomap(["apple", "banana", "apple", "orange"])
Btolist(["apple", "banana", "apple", "orange"])
Ctoset(["apple", "banana", "apple", "orange"])
Dtonumber(["apple", "banana", "apple", "orange"])
Attempts:
2 left
💡 Hint
toset() removes duplicates and creates a set.
security
expert
2:30remaining
Impact of incorrect type conversion on Terraform resource behavior
If a Terraform variable expects a number but receives a string without conversion, what is the likely outcome during plan or apply?
ATerraform raises a type mismatch error and stops the operation
BTerraform silently converts the string to number and proceeds
CTerraform ignores the variable and uses a default value
DTerraform applies the configuration but with unexpected resource behavior
Attempts:
2 left
💡 Hint
Terraform enforces strict type checking for variables.