To be honest, I still don’t understand why so many people didn’t like the experimental defaults()
function. Perhaps I just did not delve into it very much or did not want to do it, but this function satisfied all my requests. Now, when this function has been replaced by a new, supposedly simpler way to set default values (it really looks simpler, it just works in a completely different way), on the contrary, I ran into problems.
Perhaps someone can suggest how, when using the new way of setting default values for optional attributes, I can understand “who” set the values of these attributes - the users themselves in their configuration, or were the default values applied?
For example, I have a variable like this:
variable "page_rules" {
type = list(object({
page_rule_name = string
target = string
actions = object({
minify = optional(object({
html = optional(string, "off")
css = optional(string, "off")
js = optional(string, "off")
}))
mirage = optional(string)
polish = optional(string)
})
priority = optional(number)
status = optional(string)
}))
default = []
validation {
condition = alltrue(flatten([
for page_rule in var.page_rules : anytrue([
for action in page_rule.actions : action != null
])
]))
error_message = "Error details: The action object of each rule must contain at least one non-null action."
}
}
Previously, I was able to stop the user from using the following configuration simply because it doesn’t look normal and doesn’t make sense:
page_rules = [
{
page_rule_name = "rule_1"
target = "acme.com"
actions = {}
},
{
page_rule_name = "rule_2"
target = "acme.com/login"
actions = {}
}
]
However, now I can’t do that because the validation rule won’t work due to the way the default values are now applied, each actions
object will now have:
minify = {
html = "off"
css = "off"
js = "off"
}
How can I find out what exactly the user wrote in the configuration?