Variable interpolation from file()

In a template stanza, when setting the data attribute for an external file with file("somefile.txt"), I get the raw contents of the file, and no variable interpolation.

Terraform, for instance, has a function named templatefile() where it actually works the interpolation.

Is there a way to load an external file and interpolate it with my job definition’s local variables?

Hi @gcstr. Nomad template stanzas use consul-template as the underlying implementation which does not support templatefile functionality unfortunately.

Depending on your requirements, I wonder if it would be possible to embed the template within the stanza and then have this rendered by consul-template? The Nomad Autoscaler demo includes an example of this.

Thanks,
jrasell and the Nomad team

@jrasell, thanks a lot for the prompt reply.

It is definitely possible to have the full template directly in the file using heredocs, the problem is that I have two tasks in my job that use the same base template, and I’d prefer not to repeat it.

But if it’s not supported, I’ll find another way.

Thanks, jrasell