validation block

A block inside a variable that states a condition the value must meet and the error message to show when it does not.

In more detail

Validation runs before anything is planned, so a bad value stops the run with your own clear message instead of producing wrongly named resources. The condition is any expression that returns true or false.

Example

validation {
  condition     = contains(["dev", "staging", "prod"], var.environment)
  error_message = "The environment must be dev, staging or prod."
}

Related terms

Taught in

References

Certification courses