I am writing the template for a parametrized HashiCorp Nomad job. One of its parameters is priority, which is supposed to be an integer between 0 and 100.

Like other tools, Nomad supports variable interpolation, so that a variable can be defined at some point and later referenced. Nomad also allows to define "meta" variables, which are passed at runtime and can be used within the HLC file.

What I'm trying to do looks as follows:

job "my-job" {
    parametrized {
        meta_required = ["TASK_PRIORITY"]
    priority = "${NOMAD_META_TASK_PRIORITY}"

The only way I have found to read those variables are within strings. Since the priority stanza expects an integer, the following error is thrown:

error parsing 'job': 1 error(s) decoding: * cannot parse 'Priority' as int: strconv.ParseInt: parsing "${NOMAD_META_TASK_PRIORITY}": invalid syntax

Is there any way to "cast" the string to an integer? Or, alternatively, is there any other way of referencing the variable that would work?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.