-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HCL2 variables behave differently when passed via -var
and -var-file
#11149
Comments
A second case with weird results; if I break the job file on purpose: job "example" {
datacenters = ["dc1"]
group "cache" {
network {
port "db" {
to = 6379
}
}
service {
name = "test"
tags = [
"a",
"c" ### Missing comma here ###
"b",
]
}
task "redis" {
driver = "docker"
config {
image = "redis:3.2"
ports = ["db"]
}
resources {
cpu = 500
memory = 256
}
}
}
} and execute
I now also get the error for the unused variable:
|
As a sidenote: I also do not understand the error message |
Hi @apollo13 and thanks for raising this issue with such detail. Firstly, I would expect that both the plan command you describe in your first comment to behave in the same manner. This therefore indicates a bug to me in the As detailed in the Nomad hcl2 documentation, "each input variable accepted by a job must be declared using a
|
Aside from the inconsistency, would you expect |
@apollo13 I personally would, but that is just how I would expect to run Nomad job files. I did a little further digging and it does look like there is a flag internally to the hcl2 jobspec parsing which can alter this behaviour as you desire. This parameter is not currently exposed to users to toggle. I will raise a separate issue to look into exposing this. |
It appears Nomad mostly follows Terraform's lead here:
Nomad lacks the warning in the second case but the end result appears to be the same. That being said I don't really like Terraform's behavior. 😅 I feel like we should either allow or deny var files with undefined variables. While it might be nice to allow people to stuff a json file full of variables and use them only as desired (maybe the variables are defined clusterwide and jobspec authors use them as desired), I think biasing for consistency, clarity, and failing-fast is fine. We'll differ from Terraform in functionality, but not really in spirit since they discourage people from putting undefined variables in var files through their warning. Update: In #11165 for Go |
I'm going to lock this issue because it has been closed for 120 days ⏳. This helps our maintainers find and focus on the active issues. |
Nomad version
Nomad v1.2.0-dev (cf7675a+CHANGES)
Operating system and Environment details
Fedora 34
Issue
Planing a broken jobfile results in different error messages in the presence of a variable.
Reproduction steps
echo '{"TEST":"abc"}' > vars.json
nomad job plan -var-file vars.json example.nomad
-- this one plans just finenomad job plan -var TEST=abc example.nomad
-- failsThe second plan fails with:
Is this a bug or by design? If it is by design, I think the docs could do with an update that variables specified via
-var
must be consumed. Behavior-wise I would prefer it to not error out (especially not in the case of a variable file) since it seems rather common to me to supply a set of base variables in CI scripts which are not necessarily used by all jobs.Job file (if appropriate)
The text was updated successfully, but these errors were encountered: