Interview Prep/Terraform/Variables, Locals, Outputs and Types

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."
  }
}
All Terraform questions Roadmap: Terraform

More on Variables, Locals, Outputs and Types