This is not possible as the resource information is needed for scheduling, whereas the template processes are invoked once an allocation has been scheduled and placed on a client. I would suggest looking at HCLv2 variables as a possible feature to use for setting these.
Sounds like a jop for Nomad Pack / Levant. If you’re writing a task definition that needs to be templated out using data in Consul, before being submitted, maybe this would be the right approach?
Thanks @brucellino1!
We are already using Levant in templating, what I was looking for, is on a job (re)start event, the job will fetch the values from Consul.
According to ChatGPT this is possible, so I was hoping it got it from somewhere:
Yes, it is possible to set the resources values in a Nomad job specification from Consul key-value using the Consul Template.
I see - you only consume the data at submit time, when you want to consume it also at restart time. Starting to sound like a job for the streaming API:
Maybe you could use a Consul event watch
to re-template the task definition and send it directly to the Nomad API, when the job is restarted?