Given this Terraform variable with validation, what will happen if you provide the value "test"?
variable "env" {
type = string
validation {
condition = contains(["prod", "dev", "stage"], var.env)
error_message = "The environment must be one of: prod, dev, stage."
}
}Think about what happens when a variable value does not meet the validation condition.
Terraform variable validation stops the plan if the condition is false. Since "test" is not in the allowed list, it fails with the specified error message.
Consider this Terraform variable:
variable "instance_count" {
type = number
default = 3
validation {
condition = var.instance_count >= 1 && var.instance_count <= 5
error_message = "Instance count must be between 1 and 5."
}
}What happens if you set instance_count = 6 in your Terraform configuration?
Validation conditions must be true for the plan to succeed.
The validation condition requires the instance count to be between 1 and 5 inclusive. Setting it to 6 violates this, causing Terraform to fail with the error message.
You want to validate a variable vpc_cidr to ensure it is a valid CIDR block in Terraform. Which validation condition correctly checks this?
Terraform has built-in functions to test CIDR validity.
The can() function tests if cidrhost() can parse the CIDR block. This is a reliable way to validate CIDR format.
What is a potential security risk if you do NOT use validation rules on a Terraform variable that accepts a list of IP addresses for firewall rules?
Think about what happens if bad input is accepted without checks.
Without validation, users can input incorrect or harmful IP addresses, potentially exposing resources to unauthorized access.
You have a Terraform variable allowed_users that must be a list of strings and cannot be empty. Which validation block enforces this correctly?
Check both non-empty list and string format in the condition.
Option C checks that the list is not empty and that every string matches a username pattern. Other options miss one or both checks.