-
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: add alltrue & anytrue function #13237
base: main
Are you sure you want to change the base?
Conversation
3eca8c7
to
636c4f4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall LGTM, I left a couple comments mostly about the copyright/license header, and left one question on the implementation of any_true
, but besides those we're good to go.
Pre-approving this one
if !v.IsKnown() { | ||
return cty.UnknownVal(cty.Bool), nil | ||
} | ||
if v.IsNull() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we cannot declare the function as not accepting null/unknown? Though this might make sense to support them and return false immediately in that case so please feel free to push back on this comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that user of this function have good chance of being using terraform and I think we should keep consistency with the terraform
project to reduce the risk of having confusing error.
} | ||
} | ||
if hasUnknown { | ||
return cty.UnknownVal(cty.Bool), nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume this behaviour was lifted from Terraform, but I find this somewhat debatable? Since the function is called AnyTrue
, if one value is effectively true, I don't think we should care about one value being unknown in there
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with you, when I took that from terraform I found it a bit weird but I think the consistency between packer
and terraform
is more important unfortunately.
636c4f4
to
c17afbc
Compare
add an hcl2 function that return true if all the value in a collection are true, this function was derived from terraform codebase
this function add the hcl2 anytrue function which takes a collection and return true if any of the element is true.
c17afbc
to
0e25a9d
Compare
alltrue
Function that return
true
if all elements of the collection aretrue
manual tests
tested with
packer console --config-type=hcl2
anytrue
Function that return
true
if at least 1 element istrue
manual tests
tested with
packer console --config-type=hcl2
Closes #13073