You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to perform variable validation on a variable with optional values Terraform returns an error, "This object does not have an attribute named XXXX" if any of the elements in the map are not set (set to null by being optional).
Tested with Terraform 1.1.2 and 1.1.4
Code to reproduce the issue:
main.tf:
terraform {
experiments = [module_variable_optional_attrs]
}
variable "var1" {
type = map(object({
config_str = optional(string)
}))
validation {
condition = alltrue([for k in var.var1 : (k.config_str != "bad-config")])
error_message = "Config_str must not be set to 'bad-config'."
}
}
Validation should pass or fail depending on the validation rule.
Actual Behavior
Terraform returns an error. e.g.
Error: Unsupported attribute
on main.tf line 10, in variable "var1":
10: condition = (var.var1.config_str != "bad-config")
var.var1 is object with 1 attribute "config1"
This object does not have an attribute named "config_str".
Steps to Reproduce
terraform init
terraform plan
Additional Context
As a work around it is possible to use try or lookup, but it gets a little ugly. e.g:
variable "var1" {
type = map(object({
config_str = optional(string)
}))
validation {
condition = alltrue([for k in var.var1 : (lookup(k,"config_str",null) != "bad-config")])
error_message = "Config_str must not be set to 'bad-config'."
}
}
The text was updated successfully, but these errors were encountered:
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
When trying to perform variable validation on a variable with optional values Terraform returns an error, "This object does not have an attribute named XXXX" if any of the elements in the map are not set (set to null by being optional).
Tested with Terraform 1.1.2 and 1.1.4
Code to reproduce the issue:
main.tf:
terraform.tfvars:
Expected Behavior
Validation should pass or fail depending on the validation rule.
Actual Behavior
Terraform returns an error. e.g.
Steps to Reproduce
terraform init
terraform plan
Additional Context
As a work around it is possible to use try or lookup, but it gets a little ugly. e.g:
The text was updated successfully, but these errors were encountered: