hashicorp / nomad

Nomad is an easy-to-use, flexible, and performant workload orchestrator that can deploy a mix of microservice, batch, containerized, and non-containerized applications. Nomad is easy to operate and scale and has native Consul and Vault integrations.
https://www.nomadproject.io/
Other
14.94k stars 1.96k forks source link

HCL2 validation fails with: Extra characters after interpolation expression #11222

Open gabrieltz opened 3 years ago

gabrieltz commented 3 years ago

Nomad version

Output from nomad version Nomad v0.12.7 (6147cb578794cb2d0c35d68fe1791728a09bb081) ( my production env ) Not affected Nomad v1.1.3 (8c0c8140997329136971e66e4c2337dfcf932692) affected Nomad v1.1.4 affected Nomad v1.1.5 (117a23d2cdf26a1837b21c84f30c8c0f3441e927) affected

Operating system and Environment details

Ubuntu 18.04 and 20.04

Issue

hello,

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

Reproduction steps

Expected Result

Job validation successful ( with green happy characters )

Actual Result

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 also posted this at https://discuss.hashicorp.com/t/extra-characters-after-interpolation-expression/29726 and another user was able to reproduce this as well.

Thank you

nastjusha commented 3 years ago

Good👍🏻

angrycub commented 3 years ago

You can escape the $ to work around the invalid HCL2 identifier.

       attribute   = "$${meta.56net}"

This will be rendered to the proper JSON, because the HCL2 parser will just remove the "escaping" $.

        "Constraints": [
            {
                "LTarget": "${meta.56net}",
                "Operand": "=",
                "RTarget": "true"
            }
        ],
gabrieltz commented 3 years ago

thank you @angrycub

while that does validate the job propelry , it breaks nomad 0.12.7 which i am currently running in our datacenter.

I was validating all job files against the latest nomad version, to see if my job files would work on both current and latest versions of nomad before upgrading to the latest. This interpolation issue is the only one breaking so far and i have already modified more that 50 jobs to work on both versions.

I guess the only way to make it work on both versions is to rename this meta key to meatballs or anything else, across the datacenter, that doesn't start with a number :)

If it isn't a bug then you may close this issue.

thank you