hashicorp / hashicorp/nomad

"Missing" variable rules wrong when using `-var-file`

Open
#16,136 6 comments 1 reaction 0 assignees View on GitHub
stage/needs-discussion theme/cli 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.4.3 (f464aca721d222ae9c1f3df643b3c3aaa20e2da7)`

### Operating system and Environment details

`Linux ip- 5.15.0-1028-aws #32-Ubuntu SMP Mon Jan 9 12:28:07 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux`

(Ubuntu 22.04 LTS; base OS plus Nomad installed from Hashicorp repositories)

### Issue

Variables defined in a variable file, but not in a jobspec file, result in a runtime error:
```
Error getting job struct: Error parsing job file from :
: Undefined variable; A "" variable was set but was not found in known variables. To declare variable "", place this block in your job files
```

The converse (variables defined in a jobspec file, but not in a variable file) also results in a runtime error, but this is desired behavior.

### Reproduction steps

test.vars:
```
im_defined = "success"
im_undefined = "failure"
```

test.hcl:
```
variable "im_defined" {
type = string
}
job "test" {
group {
task {
}
}
}
```

`$ nomad job plan -var-file=test.vars test.hcl`

#### Expected Result

Variables defined in a file -- just like variables defined in the environment -- but not a part of the job should be ignored.

**RATIONALE**: Some variables (database passwords, service URLs, etc.) may be shared among jobs, while other variables are unique. For consistency, it would be easiest to maintain a single variable file-per-environment (`dev.vars`, `staging.vars`, `production.vars`, etc.) and use it with all job files that belong to that environment.

With the current Nomad behavior, this is impossible _unless_ all variables, including unused ones irrelevant for that particular job, are defined in the jobspec file, which makes the jobspec file cluttered.

#### Actual Result

Runtime error

### Job file (if appropriate)

See repoduction, above

### Nomad Server logs (if appropriate)

n/a

### Nomad Client logs (if appropriate)

n/a

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.