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
Lookup default value type error for map of objects with optional attributes (1.3.5 regression) #32417
Comments
Workaround is to use the default value for a typed input parameter. I don't know of any other way of explicitly expressing @@ -8,6 +8,16 @@ variable "test_count" {
default = 1
}
+variable "override_defaults" {
+ type = object(
+ {
+ foo = optional(string)
+ bar = optional(string)
+ }
+ )
+ default = {}
+}
+
variable "overrides" {
type = map(object(
{
@@ -20,6 +30,6 @@ variable "overrides" {
output "test" {
value = {
- for index in range(var.test_count) : "${var.name}${index + 1}" => lookup(var.overrides, "${var.name}${index + 1}", {})
+ for index in range(var.test_count) : "${var.name}${index + 1}" => lookup(var.overrides, "${var.name}${index + 1}", var.override_defaults)
}
}
|
Hi @SpComb, thanks for the report and the reproduction. I can confirm that I can see the same thing, and that this worked in 1.3.4, and is broken in 1.3.5 and 1.3.6. tl;dr: The correct thing for you to do here is to write your lookup as follows: So the reason this changed is we fixed a downstream bug in the type system that was leaving the metadata about optional attributes in empty collections: zclconf/go-cty#143 Even in 1.3.4 if you populated the default value of Basically, you can only specify optional attributes in type constraints. This type constraint is what you put in the This is similar to #32200. The correct thing for you to do here is to write your lookup as follows: |
This comment contains a modified reproduction that also fails in v1.3.4. I think this demonstrates this isn't a case of regression but actually a change that made empty collections and populated collections behave in the same way.
The above fails with the same error in all 1.3.* versions, and is an example of Terraform behaving in the right (if a slightly confusing) way. |
Thank you for the explanation! |
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
https://gist.github.com/SpComb/8d9cc19f6c43c3221f95c21db99c370a
Expected Behavior
terraform 1.3.4
plan
output:Actual Behavior
terraform 1.3.5
plan
error:Steps to Reproduce
terraform plan
Additional Context
No response
References
No response
The text was updated successfully, but these errors were encountered: