Nomad task env variables with dots/dashes, using the `template` stanza

hi all … i am looking for some guidance on how to declare nomad task env variables with dots/dashes – using the template stanza …

i am aware the primary way to achieve this is by using the env stanza, as described HERE

the problem with that approach is that it doesn’t allow me (or at least i haven’t been able to figure it out) to use consul-template to pull KV configs from consul …

for example, let’s assume i have in consul KV some values ::

consul kv put apps/login/some-url http://localhost/
consul kv put apps/login/some.text helloworld

what i am hoping to achieve is something like this ::

template {
  change_mode = "noop"
  destination = "local/file.env"
  env = true
  data = <<EOH
{{ range ls "apps/login" }}
{{ .Key }}={{ .Value }}
{{ end }}
EOH
}

but i end up with the error of ::

Template failed to read environment variables: error parsing env template "/opt/nomad/data/alloc/abc123/deploy/local/file.env": error on line 2: key characters must be [A-Za-z0-9_.] but found '-'

of course i can just manually set those in the env stanza using the env = {} syntax – but that means i would lose my ability to use consul-template to automatically discover and set those KV configs as env vars …

i am fine with using something like nomad-pack to achieve this, i am just not seeing a clear path on how i would be able to …

any help is appreciated …

thanks !!

after digging a little more, i think i may have found an alternative path using ::

template {
  change_mode = "noop"
  destination = "local/file.env"
  env = true
  data = <<EOH
APP_CFGS={{ tree "apps/login" | explode | toJSON }}
EOH
}

this allows me to cleanly set dynamic env vars using consul-template – while remaining compliant with env var key naming …

IF it is possible to somehow templatize the nomad task env stanza using consul-template – i would love to hear about it … maybe via nomad-pack or levant ??

thanks for listening …