How to parse variables in agent config files?

according to release notes for nomad 1.0

we can use variables in agent config fies, but whats the syntax?

in each instance below I get:

  • data-dir must be given as an absolute path: got ${var.DATA_DIR} Configuration is invalid

data_dir  = "${var.DATA_DIR}"
data_dir = ${var.DATA_DIR}
data_dir = $DATA_DIR
lol and etc

i have a data.inputs.hcl file with content like

variable "BIND_ADDR" {
  type    = string
  default = "0.0.0.0"
}

switched to using levant

Since you mentioned Levant, I’d check out this topic:

total noob to nomad, thanks,

looks like my next post will be switching to nomad pack

1 Like

Just so you’re not confused:

nomad-pack and levant are tools for rendering jobfiles (somewhat similar to helm-charts for kubernetes).

Your initial example (and release note) is related to the nomad agent config, which is not the same :slight_smile:

haha yea i figured that out at the end, wont publicly admit how long that took me…

but I ended up dropping both, felt uncomfortable using levant since future development is questionable, and nomad-pack didnt work after a few minutes (took me hours with levant (that agent vs jobspec file thing), so was frustrated)

i’m pretty comfortable with HCL so went with this setup

i couldnt get the simple_service nomad pack to work with docker compose convert

for some reason levant wouldnt consume the compose export as json nor yaml
complained about the volume syntax in both

docker compose convert | yq -r -o=json >.env.${ENV}.compose.json
docker compose convert >.env.${ENV}.compose.yaml

which looks like this for my vault setup

volumes:
    - type: bind
      source: /home/poop/git/private/nirv/core/apps/nirvai-core-vault/src/config
      target: /vault/config
      bind:
        create_host_path: true
    - type: bind
      source: /home/poop/git/private/nirv/core/apps/nirvai-core-vault/src/data
      target: /vault/data
      bind:
        create_host_path: true
    - type: bind
      source: /home/poop/git/private/nirv/core/apps/nirvai-core-letsencrypt/dev-nirv-ai
      target: /etc/ssl/certs/dev-nirv-ai
      bind:
        create_host_path: true