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?

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)
4
  • I'm afraid it does not. I get Parse Error error parsing: At 16:14: Unknown token: 16:14 IDENT int – Alexander George Sep 19 '19 at 21:46
  • @alexander what about putting it in a meta block? – LTPCGO Sep 19 '19 at 23:19
  • @LTCGO I tried that to. It all comes down to the string to int conversion not working/being supported. I'm beginning to think this is just not possible at Nomad's current state. – Alexander George Sep 19 '19 at 23:30
  • As the link says, it seems to have been fixed in 0.4. You could perhaps raise a bug there. – LTPCGO Sep 20 '19 at 0:58
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.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.