-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 length function not taking string? #14462
Comments
Hi @xorander00 and thanks for raising this issue. The current length function does indeed only support maps, lists, or tuples. I will raise a change to the documentation for this as well as add a new function to allow for calculating the length of a string. |
@jrasell No problem! I do have a quick question that overlaps with this issue. Is the HCL2 module used in nomad trailing by a few versions? I'm trying to use formatdate() with timestamp() as the 2nd argument (to use the current date/time). timestamp() is not listed in the Nomad docs, so it's not a surprise that it fails, but I do see it in the packer docs. I'm trying to use formatdate to set a local variable to a formatted date/time string when an input variable is empty. If timestamp() is not available, then I'm not sure what other function to use for it (if there is one). I could of course render it using go-template at placement time, but I'd prefer this be done during job parsing as the value will always be consistent wherever it is referenced in the job. Not sure as I'm not familiar with the codebase, but I get the feeling that maybe rebasing and updating the HCL2 implementation used in Nomad might fix a number of these types of potential issues? |
Hi @xorander00; merely importing the library is not enough to make the language and function usable. The functions in particular need to be mapped for use which means there is potential for differences between implementations. If you have a use case for adding additional HCL2 functions, I would suggest raising a new feature request so we can correctly track these along with any context you have. If you're interested in trying to raise a PR to add the function, this PR I just raised could serve as a good base for how to do it. |
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. |
Nomad version
v1.3.2
Operating system and Environment details
FreeBSD 13.1-STABLE
Issue
HCL2 length() function, according to the docs, should accept an argument of any of the following types: string, array, map, or tuple.
It seems to only accept collections though, not a string. I know I can remove the default assignment and effectively achieve the same thing, but I'd like to solve why length() isn't taking a string. I tried strlen() as well since that's in the Terraform docs and I wondered if Nomad might have a version mismatch with what's in the docs, but nope.
Reproduction steps
See above snippet.
Expected Result
Return numeric length of string.
Actual Result
HCL2 semantic error when running
nomad job validate myjob.hcl
. Complains that length() expects a map, array, or tuple.Job file (if appropriate)
The text was updated successfully, but these errors were encountered: