-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
hcl2template: don't use it's var type when the default value for a variable is empty #11559
Conversation
…riable is empty * converting something in HCL to the EmptyObject or EmptyTuple types will return a new empty object.
In theory I like the approach but I do wonder if the right thing to do here is error instead of trying EmptyObject and EmptyTuple as a non-type. I was curious how this would work if I made the default an EmptyObject and assigned it a number. ~> packer inspect /tmp
Packer Inspect: HCL2 mode
> input-variables:
var.bar: "1"
var.foo: "{\n \"key\" = \"---\"\n}"
> local-variables:
> builds: // test.auto.pkrvars.hcl
bar = 1
// test.pkr.hcl
variable "foo" {
default = {
"key" : "---"
}
}
variable "bar" {
default = {}
}
locals {
baz = merge(var.foo, var.bar)
}
|
Yeah, that is a super valid point. I opened zclconf/go-cty#122 to see if this could be a good idea. |
Note that for Terraform here, the default type is always ignored, so your example would just work. |
Yeah, I def. thought about that. TBH I think users would know better what to expect here. So I'm good with merging. If users find anything confusing we can revisit. Unless you prefer to hold until you get a response from the go-cty repo. |
Hey @nywilken, yup, I think this can be merged. I need to add tests first ! The TLDR is that the conversion to a type only ensures that the receiving type has all attributes of the 'being-converted' object, so, this is intended and will always work. So for now, I think this PR ignoring these makes sense. The next solution will be like I said in the issue to :
(which changes behavior a little, but it's okay, because in any case, it is always better to set the type for an input var) |
Closing this one in favor of #11566 to avoid conflict |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. |
In HCL, when no type is given for a var, the type of the default value will be used. But the type of
default = {}
is theEmptyObject
.Converting something in HCL to the EmptyObject or EmptyTuple types will return a new empty object. Meaning that if we try to set these later on, the result will remain something empty.
This potentially fixes #11551