Extra characters after interpolation expression

hello everyone,

when a client meta key starts with a number it breaks the hcl2 validator for a job,
hcl1 appears to work fine.

when i run nomad job validate dummy.nomad, i get the following.

Error getting job struct: Failed to parse using HCL 2. Use the HCL 1 parser with `nomad run -hcl1`, or address the following issues:
dummy.nomad:7,33-36: Extra characters after interpolation expression; Expected a closing brace to end the interpolation expression, but found extra characters.

i tested with nomad v1.1.3 and v1.1.4
Our cluster currently runs with v0.12.7, i was checking for needed changes prior to upgrade.

from nomad agent config:

client {
  enabled = true
  meta {
    "56net" = "true"
    "web"   = "true"
    "balancer" = "false"

dummy job:

# vi: tabstop=4 shiftwidth=4 expandtab
job "ajob" {
    datacenters = ["dc1"]
    type = "service"

    constraint {
        attribute   = "${meta.56net}"  /* <== this one */
        value       = "true"

    group "ahappylittlegroup" {
        count = 1

        constraint {
            operator  = "distinct_hosts"
            value     = "true"

        task "dummy" {
            driver = "docker"
            config {
                image = "whatever"

            resources {
                memory = 2048
                cpu    = 400

thank you

1 Like

Hi @gabrieltz :wave:

That’s interesting! I was able to reproduce it and it does seem like a bug in the HCL2 parser.

To go into a bit of more details, HCL2 expects identifiers to start with a letter, but Nomad doesn’t have this requirement for client meta attributes, which is what you are using.

Would you mind filing a bug report?

Thank you!

I was about to file a bug report on tuesday , but the github issues template suggested using the forum first, so since at least one more person could reproduce it , I will file a new issue

thank you for confirming this

i’m adding the github issue url below in case someone wants to track the progress.

1 Like

That’s great, thank you!

I was able to work around this issue by escaping the $ so that the HCL2 interpreter will ignore the reference. I was able to get your job to start properly on my node by setting the constraint attribute to:

        attribute   = "$${meta.56net}"  /* <== this one */

This gets expressed as the proper job constraint when rendered.

        "Constraints": [
                "LTarget": "${meta.56net}",
                "Operand": "=",
                "RTarget": "true"

Because the HCL2 parser is so strict with regard to naming, escaping the value in cases where you can’t update the values to be conforming could be a reasonable workaround.

Hopefully this helps folks!

Charlie V.