Jump into concepts and practice - no test required
or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Recall & Review
beginner
What is a tuple type in Terraform?
A tuple type in Terraform is an ordered list of elements where each element can have a different type. It is like a fixed-size list with specific types for each position.
Click to reveal answer
beginner
How do you define a tuple type with a string and a number in Terraform?
You define it as tuple([string, number]). This means the first element must be a string and the second must be a number.
Click to reveal answer
intermediate
Why use tuple types instead of lists in Terraform?
Tuples allow you to specify exact types and order for each element, which helps catch errors early and ensures data structure consistency.
Click to reveal answer
beginner
Example: What does tuple([string, number, bool]) mean?
It means a tuple with exactly three elements: first a string, second a number, and third a boolean value.
Click to reveal answer
intermediate
Can tuple elements be complex types like maps or objects in Terraform?
Yes, tuple elements can be any valid Terraform type, including maps, objects, or even other tuples.
Click to reveal answer
What does tuple([string, number]) enforce in Terraform?
AFirst element is a string, second is a number
BBoth elements must be strings
CAny two elements of any type
DOnly one element allowed
✗ Incorrect
tuple([string, number]) means the first element must be a string and the second must be a number.
Which Terraform type allows fixed order and types for elements?
ASet
BTuple
CMap
DList
✗ Incorrect
Tuple types specify fixed order and types for each element, unlike lists which allow any type.
Can a tuple in Terraform contain a boolean as an element?
AOnly if it is the last element
BNo
COnly if it is the first element
DYes
✗ Incorrect
Tuple elements can be any valid Terraform type, including booleans.
What happens if you assign a wrong type to a tuple element in Terraform?
ATerraform converts the type automatically
BTerraform ignores the error
CTerraform shows a type error during plan or apply
DTerraform crashes
✗ Incorrect
Terraform validates tuple element types and shows errors if types do not match.
Which of these is a valid tuple type definition in Terraform?
Atuple([string, number, bool])
Blist(string, number, bool)
Cmap(string, number, bool)
Dset(string, number, bool)
✗ Incorrect
Only tuple([string, number, bool]) is a valid tuple type definition.
Explain what a tuple type is in Terraform and why it is useful.
Think about how you want to keep different types in a fixed order.
You got /5 concepts.
Describe how you would define a tuple type with three elements: a string, a number, and a boolean in Terraform.
Use tuple([type1, type2, type3]) syntax.
You got /5 concepts.
Practice
(1/5)
1. What is a tuple type in Terraform?
easy
A. A fixed list of values where each value has a specific type
B. A list of values all having the same type
C. A map with keys and values of any type
D. A variable that can hold any type of data
Solution
Step 1: Understand tuple definition
A tuple in Terraform is a collection of values with a fixed number and specific types for each position.
Step 2: Compare with other types
Unlike lists, tuples have fixed length and types per position, not all the same type.
Final Answer:
A fixed list of values where each value has a specific type -> Option A
Quick Check:
Tuple = fixed types and order [OK]
Hint: Remember: tuple = fixed order and types [OK]
Common Mistakes:
Confusing tuple with list (all same type)
Thinking tuple can have variable length
Mixing tuple with map types
2. Which of the following is the correct syntax to define a tuple type with a string and a number in Terraform?
easy
A. tuple([string, number])
B. tuple[string, number]
C. list([string, number])
D. tuple(string, number)
Solution
Step 1: Recall tuple syntax
Terraform tuple types are defined as tuple([type1, type2, ...]), using square brackets inside parentheses.
Step 2: Check options
The correct syntax is tuple([string, number]). Options B and D are invalid syntax. list([string, number]) is a list, not a tuple.
Final Answer:
tuple([string, number]) -> Option A
Quick Check:
Tuple syntax = tuple([type1, type2]) [OK]
Hint: Use tuple([type1, type2]) syntax with square brackets inside parentheses [OK]
Tuple elements are indexed starting at 0. The second element is at index 1.
Step 2: Identify value at index 1
The tuple is ["hello", 42, true], so index 1 is 42.
Final Answer:
42 -> Option D
Quick Check:
Index 1 in tuple = 42 [OK]
Hint: Tuple index starts at 0, so second item is index 1 [OK]
Common Mistakes:
Confusing index 1 with index 0
Expecting string instead of number at index 1
Thinking tuple elements are unordered
4. What is wrong with this Terraform tuple type definition?
variable "bad_tuple" {
type = tuple([string, number])
default = ["text", "not a number"]
}
medium
A. The tuple type syntax is incorrect
B. The default value does not match the tuple types
C. Tuple cannot have string and number types together
D. Default value must be a map, not a list
Solution
Step 1: Check tuple type syntax
The syntax tuple([string, number]) is correct for a tuple with two elements.
Step 2: Validate default values
The default is ["text", "not a number"]. The second element should be a number but is a string, causing a type mismatch.
Final Answer:
The default value does not match the tuple types -> Option B
Quick Check:
Tuple types must match default values [OK]
Hint: Check default values match tuple types exactly [OK]
Common Mistakes:
Assuming tuple syntax is wrong
Ignoring type mismatch in default values
Thinking tuples can't mix types
5. You want to define a Terraform variable that holds a tuple with three elements: a string, a list of numbers, and a boolean. Which is the correct type definition?
hard
A. tuple(string, list[number], bool)
B. tuple(string, list, bool)
C. tuple([string, list(number), bool])
D. tuple[string, list(number), bool]
Solution
Step 1: Understand tuple element types
The tuple has three elements: a string, a list of numbers, and a boolean.
Step 2: Use correct syntax for list of numbers
In Terraform, list of numbers is written as list(number). So the tuple type is tuple([string, list(number), bool]).
Step 3: Check options
tuple([string, list(number), bool]) matches the correct syntax. Others use invalid syntax like list[number] or brackets.
Final Answer:
tuple([string, list(number), bool]) -> Option C
Quick Check:
List type inside tuple uses list(type) [OK]
Hint: Use list(type) inside tuple for lists [OK]
Common Mistakes:
Using square brackets instead of parentheses for list