How does a `validation` block work?
IntermediateConceptVariables, Locals, Outputs and Types
Answer
It runs a condition on the input and fails with your message before any resource is planned.
variable "env" {
type = string
validation {
condition = contains(["dev", "qa", "prod"], var.env)
error_message = "env must be dev, qa or prod."
}
}
More on Variables, Locals, Outputs and Types
How do you declare an input variable?BeginnerIn what order does Terraform load variable values?BeginnerHow do you define an output and what is it for?BeginnerWhat is the difference between locals and variables?BeginnerWhat are the primitive types in Terraform?BeginnerHow do list, set and map differ?Intermediate