Nomad Variables in Job Spec block key values

Is there any way to use Nomad Variables in Job Spec meta blocks?

I tried doing this and it complained:

job "test-job" {
    task "test-task" {
        meta {
          meta_test_key = {{ with nomadVar "nomad/jobs/test-job" }}{{ .nomad_variable_test_key }}{{ end }}
        }
    }
}

Naturally, using Nomad Variables in template blocks does work:

job "test-job" {
    task "test-task" {
        template {
            change_mode = "noop"
            destination = "${NOMAD_TASK_DIR}/test.json"
            data        = <<-EOT
              {{ with nomadVar "nomad/jobs/test-job" }}
              {
                "template-test": "{{ .key_test }}"
              }
              {{ end }}
            EOT
        }
    }
}

Is the template block the only jobspec block that Nomad Variables works in?

Is the template block the only jobspec block that Nomad Variables works in?

Yes.

1 Like