I've an instance type variable specified in *.tfvars and am trying to incorporate the use of the "anytrue" function however am unable to get it to work. The aim is to give users an option of four instance types and they are the only instance types to be accepted
variables.tf
variable "myinstance" {
type = list(string)
description "Select one of the following instance types - t3.medium, t3.large, t3.xlarge
or t3.2xlarge"
validation {
condition = anytrue (["t3.medium","t3.large","t3.xlarge","t3.2xlarge"],var.myinstance)
error_message = "Please select a valid instance type."
}
default = []
}
*.tfvars file = ["t3.medium"]
error message:
var.myinstance will be known only after apply.
Function "anytrue" expects only 1 argument(s)
CodePudding user response:
I think th best way would be to use setintersection:
condition = length(setintersection(["t3.medium","t3.large","t3.xlarge","t3.2xlarge"], var.myinstance)) >= length(var.myinstance)