1

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==.

I have also tried:

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

... but this generates the same encoding.

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

Edit: I've also tried the following:

HOST_ID = "${base64encode(NOMAD_ADDR_serviceA)}"

but no luck.

obviyus
  • 134
  • 1
  • 9

1 Answers1

0

@apollo13 over on the Nomad Gitter figured out a way to delay the execution of base64encode for runtime interpolation using Nomad templates. They recommend using something like:

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

Which works exactly as intended! Surprised to see that base64encode doesn't wait for the variable to become available.

obviyus
  • 134
  • 1
  • 9