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

HCL2: Add "strcontains" function support #13191

Open
jaredledvina opened this issue Oct 24, 2024 · 2 comments
Open

HCL2: Add "strcontains" function support #13191

jaredledvina opened this issue Oct 24, 2024 · 2 comments

Comments

@jaredledvina
Copy link

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Please search the existing issues for relevant feature requests, and use the
reaction feature
(https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/)
to add upvotes to pre-existing requests.

Description

I would love to see the Packer HCL2 syntax support the strcontains function similar to what is currently supported over in Terraform. This function is a really nice quick helper to do a contains comparison.

Use Case(s)

The primary use case is writing conditionals that depend on if a string is within another. For example if the source_ami name contains "test" or not.

Potential configuration

strcontains("hello world", "wor")

Potential References

https://developer.hashicorp.com/terraform/language/functions/strcontains

@jaredledvina
Copy link
Author

I attempted to start adding support for this via zclconf/go-cty#193 but completely overlooked the licensing issue. Looking at https://github.com/hashicorp/go-cty-funcs there's not an existing place that seems obvious to add support. I could just add it to https://github.com/hashicorp/packer/tree/main/hcl2template/function.

Do the maintainers have any preference for how to go about adding this?

@lbajolet-hashicorp
Copy link
Contributor

lbajolet-hashicorp commented Nov 4, 2024

Hey @jaredledvina,

This is a good idea indeed!

I see you had a chat with @apparentlymart over on CTY, he pretty much nailed it; I don't think we want to deal with potential legal issues between licenses, so do feel free to adapt Terraform's code for the function in Packer itself, no need to upstream that in a MIT project, even if it seems the better option from a technical standpoint, I don't want us to get dragged into a legal argument.
I can probably do it also later this week, your call ultimately, but if you do implement it, I'll make sure to review the PR ASAP, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants