-
Notifications
You must be signed in to change notification settings - Fork 9.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Default (optional) values in nested null object cause it to be non-null #32160
Comments
I came across a similar issue and are currently trying to figure out what I should expect. From the docs:
Especially the second paragraph seems like it initializes and applies the nested default values to the parent object, hence creating an object? |
It isn't what i expected either and the behavior completely changed between 1.3.3 and 1.3.4 so i assumed it was not intentional |
Thanks for reporting this, @slwbuild. Indeed, I think this is a regression that resulted from an attempt to address a nearby bug related to the population of default values in nested objects. Based on my understanding of the intended design here, I would expect that leaving I would expect the output you shared if you had assigned it like this: request = {
thing = {}
} ...because once I would also expect the output you shared if the type declaration included a non-null default value for variable "request" {
type = object({
thing = optional(object({
flag = optional(bool, false)
}), {})
})
} In the above case, the default value for Without either of these things being true, I would agree with you that the final value of this variable ought to have been: {
thing = null /* of object({ flag = bool }) */
} |
Here are the three cases I described above represented as code: variable "thing_default_null_unset" {
type = object({
thing = optional(object({
flag = optional(bool, false)
}))
})
default = {}
}
variable "thing_default_null_but_set" {
type = object({
thing = optional(object({
flag = optional(bool, false)
}))
})
default = {
thing = {}
}
}
variable "thing_default_obj" {
type = object({
thing = optional(object({
flag = optional(bool, false)
}), {})
})
default = {}
}
output "thing_default_null_unset" {
value = var.thing_default_null_unset
precondition {
condition = var.thing_default_null_unset.thing == null
error_message = "thing should be null."
}
}
output "thing_default_null_but_set" {
value = var.thing_default_null_but_set
precondition {
condition = !var.thing_default_null_but_set.thing.flag
error_message = "thing.flag should be false."
}
}
output "thing_default_obj" {
value = var.thing_default_obj
precondition {
condition = !var.thing_default_obj.thing.flag
error_message = "thing.flag should be false."
}
} When I run this the first output value's precondition fails:
I believe all three of these should pass, per my understanding of the design intent of this feature. |
We're seeing a similar regression from |
I think the root cause of this is the same as #32157. In the other case the problem is being exposed as a crash because the created objects are trying to be pushed into a collection which then fails as they have different types. Here it is just creating the bad objects from the nulls. |
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. |
Terraform Version
Terraform Configuration Files
Debug Output
Expected Behavior
thing should be null
Actual Behavior
thing is non-null and contains defaulted values
Steps to Reproduce
terraform plan
Additional Context
Output in TF 1.3.3 matched expected results. Changed in 1.3.4
References
No response
The text was updated successfully, but these errors were encountered: