0
0
Terraformcloud~20 mins

Type constraints in variables in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Terraform Type Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding type constraints in Terraform variables

Which Terraform variable declaration correctly restricts the variable to accept only a list of strings?

Avariable "names" { type = string }
Bvariable "names" { type = map(string) }
Cvariable "names" { type = any }
Dvariable "names" { type = list(string) }
Attempts:
2 left
💡 Hint

Think about the data structure that holds multiple string values in order.

Configuration
intermediate
2:00remaining
Identifying invalid type constraint in Terraform variable

Which variable declaration will cause a Terraform configuration error due to an invalid type constraint?

Avariable "enabled" { type = bool }
Bvariable "config" { type = map(any) }
Cvariable "settings" { type = list[object] }
Dvariable "count" { type = number }
Attempts:
2 left
💡 Hint

Check the syntax for declaring a list of objects in Terraform.

Architecture
advanced
2:30remaining
Choosing the correct type constraint for complex variable

You want to define a Terraform variable that accepts a map where each key is a string and each value is an object with two attributes: id (string) and enabled (bool). Which type constraint is correct?

Avariable "resources" { type = list(object({ id = string, enabled = bool })) }
Bvariable "resources" { type = map(object({ id = string, enabled = bool })) }
Cvariable "resources" { type = map(tuple([string, bool])) }
Dvariable "resources" { type = object({ id = string, enabled = bool }) }
Attempts:
2 left
💡 Hint

Think about the data structure: a map with string keys and object values.

security
advanced
2:30remaining
Preventing insecure input with type constraints

Which Terraform variable type constraint best prevents users from passing sensitive data as a plain string by enforcing a map with specific keys?

Avariable "credentials" { type = object({ username = string, password = string }) }
Bvariable "credentials" { type = any }
Cvariable "credentials" { type = string }
Dvariable "credentials" { type = map(string) }
Attempts:
2 left
💡 Hint

Consider how to enforce structure and keys for sensitive data.

service_behavior
expert
2:30remaining
Effect of incorrect type constraint on Terraform plan

Given the variable declaration variable "ports" { type = list(number) }, what will happen if the user provides ["80", "443"] as input during terraform plan?

ATerraform plan will fail with a type mismatch error because strings are provided instead of numbers.
BTerraform plan will succeed and convert strings to numbers automatically.
CTerraform plan will ignore the variable and use default values.
DTerraform plan will succeed but treat the ports as strings.
Attempts:
2 left
💡 Hint

Think about how Terraform enforces variable types strictly during planning.