cloudposse / terraform-aws-elasticsearch

Terraform module to provision an Elasticsearch cluster with built-in integrations with Kibana and Logstash.
https://cloudposse.com/accelerate
Apache License 2.0
218 stars 231 forks source link

Values validation doesn't work as expected #126

Closed sirantd closed 8 months ago

sirantd commented 2 years ago

Describe the Bug

Validation of availability_zone_count were introduced not far ago. It looks valid but fails if I passing

  availability_zone_count    = 2
  instance_count                 = 2

in terragrunt inputs with error:

│ Error: Invalid value for variable
│ 
│   on variables.tf line 115:
│  115: variable "availability_zone_count" {
│ 
│ The availibility zone count must be 2 or 3.
│ 
│ This was checked by the validation rule at variables.tf:120,3-13.

But if I do not provide value at all, default value 2 working good. I was able to fix it by adding tonumber() func:

variable "availability_zone_count" {
  type        = number
  default     = 2
  description = "Number of Availability Zones for the domain to use."

  validation {
    condition     = contains([2, 3], tonumber(var.availability_zone_count))
    error_message = "The availibility zone count must be 2 or 3."
  }
}

Environment (please complete the following information):

Terraform v1.1.4 on darwin_arm64

Additional Context

I'm not sure where error is, in terraform which doing casting of variables in contains function or somewhere else.

McTristan commented 2 years ago

I guess this is related to my finding mentioned here:

https://github.com/cloudposse/terraform-aws-elasticsearch/pull/122