Skip to content
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

Merged
merged 2 commits into from
Jan 21, 2025
Merged

Conversation

mogrogan
Copy link
Contributor

@mogrogan mogrogan commented Dec 19, 2024

alltrue

Function that return true if all elements of the collection are true

image

manual tests

tested with packer console --config-type=hcl2

> alltrue([true, false])
false
> alltrue(["true", true])
true
> alltrue(["true", 123])
> Error: Invalid function argument

  on <console-input> line 1:
  (source code not available)

Invalid value for "list" parameter: element 1: bool required.

anytrue

Function that return true if at least 1 element is true

image

manual tests

tested with packer console --config-type=hcl2

> anytrue([true, false])
> true
>

> anytrue([true, true])
> true
>
>
> anytrue([false, false])
> false
>

> anytrue(["true"])
> true
> anytrue(["true", 123])
> Error: Invalid function argument

  on <console-input> line 1:
  (source code not available)

Invalid value for "list" parameter: element 1: bool required.

Closes #13073

@mogrogan mogrogan changed the title hcl2template: add alltrue function hcl2template: add alltrue & anytrue function Dec 19, 2024
@mogrogan mogrogan marked this pull request as ready for review December 19, 2024 20:16
@mogrogan mogrogan requested review from a team as code owners December 19, 2024 20:16
@mogrogan mogrogan requested a review from shrhim-des December 19, 2024 20:16
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a 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

Verified

This commit was signed with the committer’s verified signature.
scorpionknifes Cheng-Zhen (CZ) Yang
add an hcl2 function that return true if all the value in a collection
are true, this function was derived from terraform codebase

Verified

This commit was signed with the committer’s verified signature.
scorpionknifes Cheng-Zhen (CZ) Yang
this function add the hcl2 anytrue function which takes a collection and
return true if any of the element is true.
Copy link
Contributor

@lbajolet-hashicorp lbajolet-hashicorp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@lbajolet-hashicorp lbajolet-hashicorp merged commit cb4965d into main Jan 21, 2025
12 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the alltrue_function branch January 21, 2025 15:07
Copy link

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.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Please add support to alltrue function
2 participants