-
Notifications
You must be signed in to change notification settings - Fork 10.3k
Not nullable module input variable validates null before default value #30307
Description
Terraform Version
1.1.2
Terraform Configuration Files
Module:
# main.tf
module "demo" {
source = "./modules/demo"
action = null
}# module/demo/variables.tf
variable "action" {
type = string
description = "Action (create, upgrade)"
default = "create"
nullable = false
validation {
condition = contains(["create", "upgrade"], var.action)
error_message = "Variable 'action' is invalid. Possible values are: ['create', 'upgrade']."
}
}Debug Output
Expected Behavior
Before validating variable value, the default value should be set as it's value, because the variable is tagged as nullable = false.
In the docs it's written that:
Setting nullable to false ensures that the variable value will never be null within the module. If nullable is false and the variable has a default value, then Terraform uses the default when a module input argument is null.
Actual Behavior
In cases where input variable has nullable argument set to false and the value passed to the variable is null, the validated value is null instead of the default value.
Steps to Reproduce
- terraform init
- terraform plan/apply
Additional context
I know there are workarounds for this problem, but shouldn't the default value be inserted into validation condition, because the default value will be used further in the module and not the null?
