Nomad variable in job


I try to configure job name from variables but it does not work. Here is an example:

My code is like this:

locals {
job_name = “iprojekt-test”

job “${local.job_name}-test” {
datacenters = [“dc1”]
type = “service”

and when I try to run this job I receive this error:

Error getting job struct: Error parsing job file from jobs/nginx-demo.nomad:
iprojekt.nomad:29,6-8: Invalid string literal; Template sequences are not allowed in this string. To include a literal “$”, double it (as “$$”) to escape it.

Here in documentation Local Values - HCL Configuration Language | Nomad by HashiCorp is the same syntax, does anyone have an idea what I do wrong?

from personal experience the HCL2 interpolation is quite a hit and miss at places.

After trying out a few things… I have settled on using Levant and templating rather than full “Terraform style” job definitions :slight_smile:

Hi @misrovy! You can’t use interpolation on block labels. See Can't use variables or locals on block labels · Issue #9522 · hashicorp/nomad · GitHub