Base64encode in Nomad jobs not working as expected

Greetings,

I’m trying to store the result of a base64encode inside an env block like so:

env {
  HOST_ID = "${base64encode("${NOMAD_ADDR_serviceA}")}"
}

Which results in HOST_ID holding the base64 encoded string “${NOMAD_ADDR_serviceA}” and not the value of NOMAD_ADDR_serviceA as I had hoped. E.g. HOST_ID = JHtOT01BRF9BRERSX3NlcnZpY2VBfQ==.

Any idea how I can reach the expected outcome? Any help would be appreciated!

Not able to test at the moment, but you could try something along the lines of this:

ref. template

template {
  destination = "/secrets/environment.sh"
  env = true
  data = <<-HEREDOC
  HOST_ID={{ env "NOMAD_ADDR_serviceA"|base64Encode }}
  HEREDOC
}

…same format might work withing the “env” block as well.

Thanks! I managed to get a solution with help from the Nomad Gitter like so:

template {
    data        = "HOST_ID={{ env \"NOMAD_ADDR_ServiceA\" | base64Encode }}"
    env         = true
    destination = "secrets/env"
}