-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Can't use variables or locals on block labels #9522
Comments
Thank @ivantopo for highlighting it. It's indeed a limitation that we want to eliminate in next few releases. We'll update the docs to call this out for now. For context, the limitation is built into HCL2 parser: https://github.com/hashicorp/hcl/blob/v2.7.2/hclsyntax/parser.go#L1637-L1638 ; and we are discussing internally removing it and how it may affect other products using HCL2. |
Thanks for the insights, @notnoop! I'll stay alert for any updates and move on without these interpolations in the meantime. |
@ivantopo by the way, there is a workaround if you're willing to have |
Mainly note that block labels need to be string literals, and that decimals without a leading significant digits aren't acceptable anymore (e.g. .9 are required to be 0.9). Dynamic blocks can be used here, but feels too much of a hack, or a hammer to highlight it here, specially given the error reporting and debugging isn't so straightforward. I'd advocate internally for relaxing the restriction and allowing expressions in block labels instead. Related to #9522
but. not to be too uppity... (divulges cards, being uppity...) the only thing not dynamic / interpolation friendly AFAICT is the we loved here's the there's just that single string substitution needed now. can live with |
perhaps worth pointing out (am sure it's known) that you can't use dynamic blocks inside docker driver config. not the end of the world and can workaround. but perhaps worth mentioning. i'm super chuffed w/ hcl v2 overall - it's super powerful and great. thanks for the behind the scenes wizardry getting that into nomad. |
Yeah, totally agree with you here. We even have to do silly things in our end-to-end testing to work around this. I don't think there's anything inherent to HCL2 that prevents block labels from being interpolated, it's a matter of spending some time to rework how we're doing the decoding a little bit. Definitely will get on the roadmap.
Thanks! That also got reported in #9871 and the fix will ship in the upcoming Nomad 1.0.4 #9921 |
thanks @tgross ! |
since this isnt added right now, this example in the docs is very confusing: https://www.nomadproject.io/docs/job-specification/hcl2/locals#examples |
Hey, can you give an estimate if this will be fixed in the next release(s)? Being |
I would like to note that this is especially an issue with container labels, both quoted and unquoted.
|
version:
|
Also tried to use local variables and use locals example from the documentation, but it still doesn't work.
job file:
|
We are currently using |
We are also using
btw, it will create a job with "foo" as it's ID and the value of bar as it's Name. |
Any update on this? Three years later, there is still no solution. |
If variables in block labels are a nogo can we at least get the option of using an unlabeled job block and specifying the id the same way we can specify the name? |
It might make sense to allow a syntax like |
this basically makes nomad-pack useless XD |
@josvegit except that Pack is able to interpolate HCL labels? There's examples in the community registry that demonstrate this exactly: https://github.com/hashicorp/nomad-pack-community-registry/blob/main/packs/democratic_csi_nfs/templates/controller.nomad.tpl#L1 Label interpolation just isn't available in Nomad natively (and as noted, it's a HCL2 parser issue, so it's non-trivial to fix without making changes that potentially impact all other HashiCorp products). If you're finding otherwise, that's probably a Pack bug. And in any case, the editorization without detail isn't particularly productive. |
@tgross Would it be possible to interpolate the job label by using a dynamic block to construct the job block? |
Nomad version
Nomad v1.0.0-rc1 (afea734)
Operating system and Environment details
Ubuntu 20.04.1 LTS
Issue
I was trying to use locals/vars to customize the name of a job, following the example in the docs but I'm getting this error:
Reproduction steps
Job file (if appropriate)
The text was updated successfully, but these errors were encountered: