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

missing support for hcl2 jobspec #179

Closed
xinau opened this issue Dec 25, 2020 · 2 comments · Fixed by #185
Closed

missing support for hcl2 jobspec #179

xinau opened this issue Dec 25, 2020 · 2 comments · Fixed by #185

Comments

@xinau
Copy link

xinau commented Dec 25, 2020

Terraform Version

$ terraform -v                 
Terraform v0.14.3
+ provider registry.terraform.io/hashicorp/nomad v1.4.11

Nomad Version

$ nomad server members
Name         Address      Port  Status  Leader  Protocol  Build  Datacenter  Region
test.global  192.168.1.2  4648  alive   true    2         1.0.1  dc1         global

Provider Configuration

provider "nomad" {
  address   = "https://test.example.com:4646"
  ca_file   = "${path.root}/../private/nomad-ca.pem"
  cert_file = "${path.root}/../private/nomad-cli.pem"
  key_file  = "${path.root}/../private/nomad-cli-key.pem"
}

Affected Resource(s)

  • nomad_job
  • nomad_job_parser

Terraform Configuration Files

resource "nomad_job" "main" {
  jobspec = file("${path.root}/jobspec.hcl")
}
...
      template {
        data          = file("./prometheus.yml")
        destination   = "local/config/prometheus.yml"
        change_mode   = "signal"
        change_signal = "SIGHUP"
      }
...

Expected Behavior

1 resource created.

Actual Behavior

$ terraform apply                                             

Error: error parsing job: &errors.errorString{s:"Unexpected response code: 400 (input.hcl:30,25-30: Error in function call; Call to function \"file\" failed: filesystem function disabled.\ninput.hcl:30,25-30: Unsuitable value type; Unsuitable value: value must be known\ninput.hcl:37,23-28: Error in function call; Call to function \"file\" failed: filesystem function disabled.\ninput.hcl:37,23-28: Unsuitable value type; Unsuitable value: value must be known\ninput.hcl:42,23-28: Error in function call; Call to function \"file\" failed: filesystem function disabled.\ninput.hcl:42,23-28: Unsuitable value type; Unsuitable value: value must be known\ninput.hcl:47,23-28: Error in function call; Call to function \"file\" failed: filesystem function disabled.\ninput.hcl:47,23-28: Unsuitable value type; Unsuitable value: value must be known)"}

Steps to Reproduce

  1. terraform apply

Important Factoids

HCL2 Language Support

@spol-ihq
Copy link

spol-ihq commented Dec 29, 2020

Same here,

Adding variables {} block at the top of the elasticsearch.hcl.template and using dynamic group {}:

variables {
  volumes_map = ["0", "1"]
}

job "elasticsearch {

(...)

Results in:

Error: error parsing jobspec: 1 error occurred:
	* invalid key: variables

  on nomad_jobs.tf line 14, in resource "nomad_job" "elasticsearch":
  14: resource "nomad_job" "elasticsearch" {

@lgfa29
Copy link
Contributor

lgfa29 commented Jan 16, 2021

Thanks for the report @xinau!

@thiagonache updated our jobspec parser to use the HCL2 version from Nomad, and the fix will be available in the next release that will come out soon.

But HCL2 parsing is a bit more complex, so not everything is compatible yet. Your specific case (calling the file HCL2 function in the Nomad jobspec) is unfortunately not covered on #185.

Since the HCL2 spec is quite big, I created a new issue to track this specific functionality (#191).

@spol-ihq your use case should work in the next release 🎉

If there are any other HCL2 related problems please open a new issue.

Thank you all once again 😄

UPDATE: after some testing, it seems like only the file function doesn't work properly. I've updated #191 to reflect this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants