Complete the code to add a validation block that ensures the variable is not empty.
variable "region" { type = string validation { condition = [1] error_message = "Region cannot be empty." } }
The validation condition must check that the variable is not an empty string to ensure a value is provided.
Complete the code to validate that the number variable is greater than zero.
variable "instance_count" { type = number validation { condition = [1] error_message = "Instance count must be greater than zero." } }
The condition must ensure the number is greater than zero to be valid.
Fix the error in the validation condition to check if the string variable is one of allowed values.
variable "environment" { type = string validation { condition = contains(["dev", "staging", "prod"], [1]) error_message = "Environment must be dev, staging, or prod." } }
The variable must be referenced with 'var.' prefix to access its value inside the validation block.
Fill both blanks to validate a list variable has at least two items and all are strings.
variable "zones" { type = list(string) validation { condition = length([1]) >= 2 && alltrue([for z in [2] : length(z) > 0]) error_message = "Zones list must have at least two valid strings." } }
Both blanks must reference the variable with 'var.zones' to check its length and iterate over its items.
Fill all three blanks to validate a map variable keys and values meet conditions.
variable "tags" { type = map(string) validation { condition = alltrue([for k, v in [1] : length(k) > 0 && length(v) [2] 0 && v != [3]]) error_message = "Tags keys and values must be non-empty strings and values cannot be 'none'." } }
The condition iterates over 'var.tags', checks keys length > 0, values length > 0, and values not equal to 'none'.