0
0
Terraformcloud~10 mins

Type conversion functions in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert the string "123" to a number.

Terraform
number_value = [1]("123")
Drag options to blanks, or click blank then click option'
Atonumber
Btostring
Ctolist
Dtomap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Forgetting to use a conversion function.
2fill in blank
medium

Complete the code to convert the number 456 to a string.

Terraform
string_value = [1](456)
Drag options to blanks, or click blank then click option'
Atostring
Btonumber
Ctolist
Dtomap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tonumber' instead of 'tostring'.
Using list or map conversion functions by mistake.
3fill in blank
hard

Fix the error in the code to convert a list of strings to a list of numbers.

Terraform
numbers = [for s in string_list : [1](s)]
Drag options to blanks, or click blank then click option'
Atostring
Btonumber
Ctolist
Dtomap
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' which converts to string, not number.
Using 'tolist' or 'tomap' which are for collections.
4fill in blank
hard

Fill both blanks to convert a map of strings to a map of numbers.

Terraform
numbers_map = { for k, v in string_map : k => [1](v) if [2](v) != null }
Drag options to blanks, or click blank then click option'
Atonumber
Btostring
Dlength
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Using 'length' which returns number of characters, not conversion.
5fill in blank
hard

Fill all three blanks to convert a list of mixed strings to a list of numbers, skipping invalid entries.

Terraform
valid_numbers = [for s in mixed_list : [1](s) if [2](s) != null and [3](s) != ""]
Drag options to blanks, or click blank then click option'
Atonumber
Ctrimspace
Dtostring
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'tostring' instead of 'tonumber'.
Not trimming spaces before checking for empty strings.