Skip to content

Variable validation of type number fails #29899

@Wuzyn

Description

@Wuzyn

Terraform Version

Terraform v1.0.10
on darwin_amd64
+ provider registry.terraform.io/hashicorp/null v3.1.0

Terraform Configuration Files

variable "my_number" {
  type = number
  validation {
    condition = contains([1, 2, 3], var.my_number)
    error_message = "Failed."
  }
}

resource "null_resource" "this" {

}

Debug Output

https://gist.github.com/Wuzyn/2d3c435df178ba8147f10b8c0430d6fb

Expected Behavior

Running terraform plan/apply and providing value from condition list should pass the validation

Actual Behavior

terraform plan
var.my_number
  Enter a value: 1

╷
│ Error: Invalid value for variable
│
│   on main.tf line 1:
│    1: variable "my_number" {
│
│ Failed.
│
│ This was checked by the validation rule at main.tf:3,3-13.
╵

Steps to Reproduce

  1. terraform init
  2. terraform plan
  3. Provide correct value, which should pass validation

Additional Context

References

Metadata

Metadata

Labels

bugconfigconfirmeda Terraform Core team member has reproduced this issueexplaineda Terraform Core team member has described the root cause of this issue in code

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions