0
0
Terraformcloud~20 mins

Why complex types matter in Terraform - Challenge Your Understanding

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

Which of the following Terraform variable declarations correctly defines a variable that expects a list of maps, where each map contains a string key and a number value?

Avariable "example" { type = list(map(number)) }
Bvariable "example" { type = map(list(number)) }
Cvariable "example" { type = list(object({ key = string, value = number })) }
Dvariable "example" { type = map(object({ key = string, value = number })) }
Attempts:
2 left
💡 Hint

Think about the structure: a list of maps means the outer container is a list, and each item is a map with string keys and number values.

Configuration
intermediate
2:00remaining
Outputting a complex type in Terraform

Given the following Terraform variable declaration, which output block correctly outputs the first map's value for the key "port"?

variable "servers" {
  type = list(map(number))
  default = [
    { port = 8080, id = 1 },
    { port = 9090, id = 2 }
  ]
}
Aoutput "first_port" { value = var.servers[0].port }
Boutput "first_port" { value = var.servers["port"][0] }
Coutput "first_port" { value = var.servers.port[0] }
Doutput "first_port" { value = var.servers[0]["port"] }
Attempts:
2 left
💡 Hint

Remember that var.servers is a list of maps, so you access the first element by index, then the map key.

Architecture
advanced
2:30remaining
Choosing complex types for modular Terraform design

You are designing a Terraform module that manages multiple cloud resources. You want to pass a variable that holds a list of resources, each with a name (string), count (number), and tags (map of strings). Which variable type best fits this requirement?

Aobject({ name = string, count = number, tags = map(string) })
Blist(object({ name = string, count = number, tags = map(string) }))
Clist(map(string))
Dmap(object({ name = string, count = number, tags = list(string) }))
Attempts:
2 left
💡 Hint

Consider the structure: multiple resources means a list, each resource has multiple attributes including a map for tags.

security
advanced
2:30remaining
Security implications of complex types in Terraform variables

Which of the following statements about using complex types in Terraform variables is true regarding security best practices?

AComplex types automatically encrypt sensitive data stored in variables without additional configuration.
BUsing simple string variables is always safer than complex types because they are easier to audit.
CTerraform variables with complex types cannot be marked as sensitive, so they should not be used for secrets.
DUsing complex types like objects allows you to enforce strict schemas, reducing the risk of misconfiguration that could expose sensitive data.
Attempts:
2 left
💡 Hint

Think about how strict typing helps prevent mistakes that could lead to security issues.

service_behavior
expert
3:00remaining
Behavior of Terraform when complex type variable input is invalid

Given a Terraform variable declared as variable "config" { type = object({ host = string, ports = list(number) }) }, what happens if you provide the following input?

{ host = "example.com", ports = ["80", 443] }
ATerraform plan fails with a type mismatch error because "80" is a string, not a number.
BTerraform plan succeeds and converts "80" string to number automatically.
CTerraform plan ignores the invalid port and uses only 443.
DTerraform plan succeeds but warns about the string in the ports list.
Attempts:
2 left
💡 Hint

Terraform enforces strict typing and does not perform automatic type conversion.