is it possible to use validation of a variable type equals list(string)?
My example:
main.tf
name = "tf-prd-sg-foo"
image_id = "ami-00e788542ee66c64f"
instance_type = "m5.xlarge"
security_groups = ["sg-000000", "sg-00000000"] # Example of SG only to contextualize
}
vars.tf
variable "security_groups" {
type = list(string)
default = []
description = "(Optional) A list of associated security group IDS."
validation {
condition = can(regex("^sg-", var.security_groups))
error_message = "The Security Groups need starts to \"sg-\"."
}
}
When I try execute returns the following error:
[terragrunt] 2021/01/05 17:12:10 Running command: terraform plan
Error: Invalid value for variable
on vars.tf line 21:
21: variable "security_groups" {
The Security Groups need starts to "sg-".
This was checked by the validation rule at vars.tf:26,5-15.
[terragrunt] 2021/01/05 17:12:12 Hit multiple errors:
exit status 1