Skip to content
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

error parsing job file #400

Open
tcurdt opened this issue Mar 10, 2021 · 13 comments
Open

error parsing job file #400

tcurdt opened this issue Mar 10, 2021 · 13 comments
Assignees
Labels
theme/template Relates to templating in general type/enhancement
Milestone

Comments

@tcurdt
Copy link

tcurdt commented Mar 10, 2021

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
@tcurdt
Copy link
Author

tcurdt commented Mar 10, 2021

Could this be related? #391

@cgbaker
Copy link
Contributor

cgbaker commented Mar 10, 2021

@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 -

@tcurdt
Copy link
Author

tcurdt commented Mar 10, 2021

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.

@cgbaker
Copy link
Contributor

cgbaker commented Mar 10, 2021

thanks, @tcurdt. will leave this open as we roadmap this.

@pznamensky
Copy link
Contributor

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 (hashicorp/nomad#4606) it would be very helpful to add hcl2 support in levant or separate deployment part as @tcurdt suggested.

@alexdulin
Copy link

If you build levant from the branch in #398 that job file will successfully parse and plan.

@pznamensky
Copy link
Contributor

Are there any news? 🙂
Alex Dulin's PR seems to be working fine.

@fliiiix
Copy link

fliiiix commented May 18, 2021

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.

@fliiiix
Copy link

fliiiix commented May 23, 2021

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: hashicorp/nomad#3760

@alexdulin
Copy link

@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"
}

@fliiiix
Copy link

fliiiix commented May 24, 2021

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.

@pavel-z1
Copy link

pavel-z1 commented Apr 9, 2022

Any updates on this?
I am also have error with parsing HCL2 locals

@sashayakovtseva
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/template Relates to templating in general type/enhancement
Projects
None yet
Development

No branches or pull requests

8 participants