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
variable"input" {
type =list(object({
a =string# a required attribute
b =optional(string) # an optional attribute
c =optional(number, 127) # an optional attribute with default value
d =optional(list(any))
}))
default = [
{ a ="a" }, { a ="b", d = [1] }
]
}
output"out" {
value =var.input
}
Without variable override it should use default value
Actual Behavior
Error: Invalid default value for module argument
on 1.tf line 1:
1: variable "input" {
The default value for variable "input" is incompatible with its type
constraint: element types must all match for conversion to list.
Steps to Reproduce
terraform init
terraform plan
run command: tf plan -var "input=[{a=1},{a=2, d=[]}]" tf plan -var "input=[{a=1},{a=2, d=[1]}]" tf plan -var "input=[{a=1},{a=2}]" tf plan -var "input=[{a=1}]" tf plan
Additional Context
It works if you apply one of these:
remove the 1 from the b=[1] so it will be an empty list
use optional default value d = optional(list(any), [])
change type any to number like d = optional(list(number))
References
No response
The text was updated successfully, but these errors were encountered:
Thanks for the well-written bug report. This shouldn't be happening: a null list should be compatible with a concrete list(number) regardless of initial type constraint. It's interesting to see it works with an empty list - perhaps cty should handle null and empty lists similarly in this case. Will investigate upstream.
@seggcsont, I'm curious as to why you use list(any) here instead of list(number) - could you say more about your use case?
kmoe
added
cty
Use in conjunction with "upstream" when cty is the relevant upstream
v1.3
Issues (primarily bugs) reported against v1.3 releases
and removed
new
new issue not yet triaged
labels
Nov 4, 2022
@seggcsont, I'm curious as to why you use list(any) here instead of list(number) - could you say more about your use case?
In my real case it is a list complex object and I do not really use any. I wanted to create a small peace of that code to try out something and I faced this issue.
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.
Terraform Version
Terraform Configuration Files
Debug Output
https://gist.github.com/seggcsont/e7a04c37155e876c4868e9acdc46268b
Expected Behavior
Without variable override it should use default value
Actual Behavior
Error: Invalid default value for module argument
on 1.tf line 1:
1: variable "input" {
The default value for variable "input" is incompatible with its type
constraint: element types must all match for conversion to list.
Steps to Reproduce
terraform init
terraform plan
tf plan -var "input=[{a=1},{a=2, d=[]}]"
tf plan -var "input=[{a=1},{a=2, d=[1]}]"
tf plan -var "input=[{a=1},{a=2}]"
tf plan -var "input=[{a=1}]"
tf plan
Additional Context
It works if you apply one of these:
1
from theb=[1]
so it will be an empty listd = optional(list(any), [])
any
tonumber
liked = optional(list(number))
References
No response
The text was updated successfully, but these errors were encountered: