1

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?

2 Answers2

1

This seems to have been an issue at some point that was fixed, but presuming you are on the most recent version this should work:

prioritystr = "${NOMAD_META_TASK_PRIORITY}"
priority = int(prioritystr)
LTPCGO
  • 472
  • 1
  • 3
  • 15
0

I ended up raising an issue on Github. Their response is that it's not yet possible to interpolate the priority field. See issue.