Terraform Stacks input variable validation
Introduced 2026-04-29 · score 0.95
HOW TO USE IT
When a Terraform Stack input variable needs a rule before planning proceeds, add a `validation` block to that variable; its `condition` must reference that variable as `var.<NAME>` and resolve to a boolean.
variable "prefix" {
type = string
validation {
condition = length(var.prefix) > 5
error_message = "prefix must be longer than 5 characters."
}
}WHY THIS HELPS
Validate an input variable in a Terraform Stack before its value reaches a provider.
REQUIREMENTS AND LIMITATIONS
- Version: 1.15.0
- validation.condition (required): Expression that must evaluate to true for Terraform to proceed. For this Stack feature, it references the containing variable as `var.<NAME>` and resolves to a boolean.
- validation.error_message (required): String displayed if the condition evaluates to false.
- Terraform version (required): Use Terraform v1.15.0 or later for Stack input variable validation.
- Prerequisite: Terraform v1.15.0 introduced input variable validation for Stacks.
- The condition expression can reference the `var.<NAME>` value for the variable that contains it and resolves to a boolean.
FIRST-PARTY EVIDENCE
- https://github.com/hashicorp/terraform/releases/tag/v1.15.0
- https://github.com/hashicorp/terraform/pull/38240
- https://developer.hashicorp.com/terraform/language/block/variable
Check the installed version and the source before using it. Entry JSON