HCL2 functions in heredocs

Is it possible to use HCL2 functions in a heredoc?

template {
  change_mode   = "noop"
  destination   = "${NOMAD_TASK_DIR}/config.yaml"
  data          = <<-EOT

    - vault_hostname: "substr({{ env "VAULT_ADDR" }}, 8, strlen({{ env "VAULT_ADDR"  }}))"


Returns an error:

err="parsing YAML file /local/config.yaml: \"substr(https://vault.hostname.com:8200, 8, strlen(https://vault.hostname.com:8200))\" is not a valid hostname"

Decided to just use Go templating syntax. This worked:

- vault_hostname: "{{ slice (env "VAULT_ADDR") 8 }}"

Hi @SunSparc,

HCL2 is not supported within the template block I am afraid. The HCL2 interpolation happens locally when you run a command such as nomad job run <job_file> whereas the template blocks are rendered on the client using the consul-template library which uses Go template syntax.

jrasell and the Nomad team