hashicorp / hashicorp/nomad

Can't use variables or locals on block labels

Open
#9,522 21 comments 30 reactions 0 assignees View on GitHub
stage/accepted theme/hcl type/enhancement
Dominant language
Go
Stars
17k
Forks
2.1k
Avg merge
1d 9h
Merged PRs (30d)
105

Description

### Nomad version
Nomad v1.0.0-rc1 (afea734825ebaade422bbf2d31364abff6def928)

### Operating system and Environment details
Ubuntu 20.04.1 LTS

### Issue
I was trying to use locals/vars to customize the name of a job, following the [example in the docs](https://www.nomadproject.io/docs/job-specification/hcl2/locals#examples) but I'm getting this error:

```
Error getting job struct: Error parsing job file from locals-bug.nomad:
locals-bug.nomad:10,6-8: Invalid string literal; Template sequences are not allowed in this string. To include a literal "$", double it (as "$$") to escape it., and 2 other diagnostic(s)
```
### Reproduction steps
- Define variables and/or locals in a job file
- Try to interpolate any variable and/or locals on the job name label.

### Job file (if appropriate)
```
variables {
name = "app"
suffix = "cluster"
}

locals {
job_name = "${var.name}_${var.suffix}"
}

job "${local.job_name}" {
datacenters = [ "FSN" ]

group "app-nodes" {
count = 3

task "app-node" {
driver = "docker"

config {
network_mode = "host"
image = "hello-world:latest"
}
}
}
}

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the provided job file and the linked HCL2 locals example, then run the reproduction against Nomad v1.0.0-rc1 to inspect the parser diagnostics. Trace how interpolation is handled in the job name label compared with locals and variables. Done means the reproduced job parses successfully with variables or locals interpolated in its name.

Written by the indexing model from the issue text.

Assessment

Domain
devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.