levant
levant copied to clipboard
error parsing job file
Description
For now I am trying to use levant
with a static job hcl
file.
While it works perfectly fine to run that job through nomad
directly, levant
fails parsing it.
Relevant Nomad job specification file
$ cat job.hcl
variables {
domain = "dev.foo.com"
database = "foo"
version = "staging"
}
job "backend-staging" {
datacenters = [ "foo" ]
group "backend" {
count = 1
network {
port "nodejs" {
host_network = "private"
}
}
service {
name = "backend-staging"
port = "nodejs"
tags = [
"traefik.enable=true",
"traefik.http.routers.backend.tls=true",
"traefik.http.routers.backend.tls.certresolver=le",
"traefik.http.routers.backend.entrypoints=websecure",
"traefik.http.services.backend.loadbalancer.server.port=${NOMAD_PORT_nodejs}",
"traefik.http.routers.backend.rule=Host(`${var.domain}`) && PathPrefix(`/api`)",
]
}
task "nodejs" {
driver = "docker"
env = {
NODE_ENV = "production"
NODE_ADDRESS = "${NOMAD_IP_nodejs}"
NODE_PORT = "${NOMAD_PORT_nodejs}"
MONGODB_URI = "mongodb://127.0.0.1:27017"
MONGODB_DB_NAME = var.database
}
config {
image = "registry.gitlab.com/foo/backend:${var.version}"
network_mode = "host"
ports = [ "nodejs" ]
}
}
}
}
Output of levant version
:
$ ./levant version
Levant v0.2.9
Date: 2019-12-27T09:43:30Z
Commit: 0f1913ea3d77584ddd0696da429dcf05572a73a0
Branch: 0.2.9
State: 0.2.9
Summary: 0f1913ea3d77584ddd0696da429dcf05572a73a0
Output of consul version
:
$ consul version
Consul v1.9.4
Revision 10bb6cb3b
Output of nomad version
:
$ nomad version
Nomad v1.0.4 (9294f35f9aa8dbb4acb6e85fa88e3e2534a3e41a)
Debug log outputs from Levant:
$ ./levant plan job.hcl
[ERROR] levant/command: error parsing: At 45:27: Unknown token: 45:27 IDENT var.database
Could this be related? https://github.com/hashicorp/levant/issues/391
@tcurdt , #391 is just a query about whether to use Levant or HCL2. But you've captured the root of the problem; Levant currently doesn't support HCL2 parsing.
i think if you need levant + HCL2, you'll need to do:
levant render ... | nomad job run -
That's what I figured :-/ But I am not really after the templating at all. Rather a better command line experience when running jobs (especially when running from CI/CD).
Why does this need parsing at all? Maybe it would be better to separate the rendering from the deployment part?
Anyway. Would be great to add the lack of HCL2 to the README. At least to me this wasn't obvious at all.
thanks, @tcurdt. will leave this open as we roadmap this.
I'm faced with the same issue. We're using levant as a deployment watcher in our CI, and it blocks further steps until a deployment successfully finish, which is super useful for us. I really hoped that the latest release is compatible with nomad 1.0, but it is not. Since nomad itself can't wait for a deployment to finish (https://github.com/hashicorp/nomad/issues/4606) it would be very helpful to add hcl2 support in levant or separate deployment part as @tcurdt suggested.
If you build levant from the branch in https://github.com/hashicorp/levant/pull/398 that job file will successfully parse and plan.
Are there any news? :slightly_smiling_face: Alex Dulin's PR seems to be working fine.
Any updates on this?
I just hit the same issue with missing hcl2 support:
[ERROR] levant/command: error parsing 'job': 1 error occurred:
* group: 'terminator-raw', task: 'build', artifact -> invalid key: headers
I tested the pr from @alexdulin which worked fine for me.
I guess I found a edge case:
Argument or block definition required; An argument or block definition is required here. To set an argument, use the equals sign "=" to introduce the argument value.
If you use env with a dot character like this:
env {
discovery.type="single-node"
}
I think nomad can handle that: https://github.com/hashicorp/nomad/pull/3760
@fliiiix I think that what you are running into is one of the quirks of HCL2 outlined in the backward compatibilities. However, you can still get your env
block to work as you want if you change it to this:
env = {
"discovery.type" = "single-node"
}
I thought I tried that but apparently there is a difference between env {}
and env = {}
the first one fails with:
[ERROR] levant/command: elasticsearch.hcl:37,11-12: Invalid argument name; Argument names must not be quoted.
But fair enough if that's a hcl2 limitation.
Any updates on this? I am also have error with parsing HCL2 locals
Having the same issue with https://developer.hashicorp.com/nomad/docs/v1.4.x/job-specification/template#wait
$ levant plan test.hcl
[ERROR] levant/command: error parsing 'job': 1 error occurred:
* group: 'group-name', task: 'task-name', template -> invalid key: wait