Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to define a variable with a description.
Terraform
variable "region" { type = string description = [1] }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using variable name instead of a description string
Omitting quotes around the description
✗ Incorrect
The description field must be a string describing the variable's purpose.
2fill in blank
mediumComplete the code to add a validation rule that ensures the variable is not empty.
Terraform
variable "environment" { type = string validation { condition = [1] error_message = "Environment cannot be empty." } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Checking for equality with empty string instead of length
Using null checks which are not appropriate for strings
✗ Incorrect
The condition checks that the length of the string is greater than zero to ensure it is not empty.
3fill in blank
hardFix the error in the validation condition to allow only values 'dev', 'staging', or 'prod'.
Terraform
variable "stage" { type = string validation { condition = contains([[1]], var.stage) error_message = "Stage must be one of: dev, staging, prod." } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string instead of a list
Omitting square brackets around the list
✗ Incorrect
The contains function requires a list as the first argument, so the values must be inside square brackets.
4fill in blank
hardFill both blanks to validate a number variable is between 1 and 10 inclusive.
Terraform
variable "instance_count" { type = number validation { condition = var.instance_count [1] 1 && var.instance_count [2] 10 error_message = "Instance count must be between 1 and 10." } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using strict greater than or less than which excludes boundary values
Swapping the operators
✗ Incorrect
The variable must be greater than or equal to 1 and less than or equal to 10.
5fill in blank
hardFill all three blanks to validate a list variable contains only allowed strings.
Terraform
variable "allowed_zones" { type = list(string) validation { condition = alltrue([for zone in var.allowed_zones : zone [1] [[2]]]) error_message = "Zones must be one of the allowed values." } }
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' incorrectly as an operator instead of a function
Not using a for expression to check each item
Providing the wrong list of zones
✗ Incorrect
The code uses a for expression to check each zone is in the allowed list using the 'in' operator, and alltrue to ensure all pass. The list of allowed zones is provided as the second argument to contains.