0

In my job definition, I have the following template:

variables {
  environment = "staging"
}

...
    task "server" {
      template {
        data        = file("vars.env")
        destination = "secrets/file.env"
        env         = true
      }
...

And my vars.env have something like

ENVIRONMENT=${var.environment}

But the template doesn't get the interpolated string, only the raw text from the file. Is there a way to tell nomad to use the local variables when parsing the vars.env file?

gcstr
  • 1,466
  • 1
  • 21
  • 45

2 Answers2

0

A different approach to resolving this could be to use the artifact stanza to download the vars.env file, and then reference the downloaded artifact from your template stanza. In doing do, with the "source" attribute instead of "data", the file's contents are passed to the template engine to be processed.

https://www.nomadproject.io/docs/job-specification/template#remote-template

  • Good point. It just seems too much work to have the file deployed somewhere instead of processing a local one :( – gcstr Nov 22 '21 at 19:58
  • That is also a reason why I haven't done this yet myself. :) Up until now, I've been using HEREDOC in my templates (instead of the file function like you've done in your example) with the data attribute, which does result in very long jobspec files. I'm considering using this method though by storing my config files in Git, and using the artifact stanza's ability to pull from there and template my values properly. – paladin-devops Nov 22 '21 at 21:31
0

Looks like this is not possible. Vars in file templates are not interpolated.

user2650367
  • 393
  • 3
  • 6