Recall & Review
beginner
What is the purpose of type constraints in Terraform variables?
Type constraints ensure that variables only accept values of a specific type, like string, number, list, or map. This helps prevent errors by validating input before applying changes.
Click to reveal answer
beginner
How do you declare a variable with a string type constraint in Terraform?
You declare it like this:
variable "example" {
type = string
} This means the variable only accepts string values.Click to reveal answer
beginner
What happens if you assign a wrong type to a Terraform variable with a type constraint?
Terraform will show an error during plan or apply, stopping the process. This protects your infrastructure from invalid configurations.
Click to reveal answer
intermediate
How can you specify a list of numbers as a variable type in Terraform?
Use the syntax:
variable "numbers" {
type = list(number)
} This means the variable must be a list where each item is a number.Click to reveal answer
intermediate
Explain the difference between 'map(string)' and 'object' type constraints in Terraform variables.
'map(string)' means a collection of key-value pairs where each value is a string. 'object' defines a fixed structure with named attributes and their types, like a small form with specific fields.
Click to reveal answer
Which Terraform variable type constraint accepts only true or false values?
✗ Incorrect
The 'bool' type constraint only accepts boolean values: true or false.
How do you declare a variable that must be a map with string values in Terraform?
✗ Incorrect
The syntax 'map(string)' means a map where each value is a string.
What will happen if you assign a list of strings to a variable declared as 'list(number)'?
✗ Incorrect
Terraform enforces type constraints strictly and will error if types don't match.
Which type constraint allows defining a fixed structure with named attributes in Terraform?
✗ Incorrect
'object' type lets you define a fixed set of named attributes with their own types.
What is the default type of a Terraform variable if no type constraint is specified?
✗ Incorrect
If no type is set, Terraform treats the variable as 'any' type, accepting any value.
Describe how type constraints improve Terraform variable usage and give examples of common types.
Think about how specifying types helps avoid mistakes before applying changes.
You got /7 concepts.
Explain how to declare a variable for a list of objects with specific attributes in Terraform.
Consider how to enforce structure inside a list.
You got /4 concepts.