nomad icon indicating copy to clipboard operation
nomad copied to clipboard

HCL2: Support user defined blocks and importing other files

Open notnoop opened this issue 4 years ago • 16 comments
trafficstars

For compliance and consistency across jobs in a company, it's very useful to have a library of tasks/configuration that job submitters can invoke. Terraform has module system to enable such capability, though it may be an overkill for Nomad. Consider using Terraform approach or introduce a lightweight alternative.

Straw-man Proposal

Support include keyword that imports an external HCL file and embed a parsed version in-place. We can support passing variables and local (scoped to the file).

For example, if an organization standardized on nginx sidecar, then they can declare a template file like:

variable "image" {
  default = "nginx:1.19"
}

task "nginx-sidecar" {
  driver = "docker"
  config { .... }
}

Then, to include that task, one can just add include "path/to/sidecar-nginx.hcl" {} with an option to set the image default: include "path/to/sidecar-nginx.hcl" { image = "nginx:1.18" }

More sophisticated module

A more complicated proposal may allow for defining a user defined block, allowing for multiple defined blocks in a file. For example, the above task can be declared

module "nginx_sidecar" {
  variable "image" { default = "nginx:1.19" }

  content {
    task "nginx-sidecar" {
      driver = "driver"

      config { ... }
    }
  }
}

User can then invoke these modules and have the parser embed the content in-place, e.g. nginx_sidecar { image = "..." } to achieve the same effect as above. The CLI can search for these modules in files in current paths, or in a specific environment variables, or through import statements in file, or another mechanism.

notnoop avatar Dec 04 '20 20:12 notnoop

linking to https://github.com/hashicorp/nomad/issues/7954

cgbaker avatar Dec 04 '20 21:12 cgbaker

and linking to prior art: https://pkg.go.dev/github.com/hashicorp/hcl2/ext/include

cgbaker avatar Dec 04 '20 21:12 cgbaker

Looking for this as well

Oloremo avatar May 05 '21 22:05 Oloremo

Add one more vote for this.

schemmer avatar Jul 11 '21 03:07 schemmer

Another vote for this

digi-talo avatar Aug 30 '21 13:08 digi-talo

Another vote for this

Dup4 avatar Nov 29 '22 05:11 Dup4

This would be highly appreceated. At the moment variable definitions are duplicated around multiple job-specifications. Having the possibility to declare them once and then include-them would simplify the maintenance of a bunch of job-specifications. See also https://github.com/angrycub/nomad_example_jobs/tree/main/HCL2/variable_jobs/env-vars

fraenku avatar Dec 05 '22 11:12 fraenku

another vote for this

gjrtimmer avatar Jan 24 '24 10:01 gjrtimmer

Another vote.

jeteve avatar Mar 19 '24 11:03 jeteve

Definite vote for this 👍

tryggvifreyrs avatar Mar 19 '24 12:03 tryggvifreyrs

Another vote

ellertf avatar Mar 19 '24 12:03 ellertf

Vote for this

hjorleifurro avatar Mar 19 '24 13:03 hjorleifurro

+1 vote

steinnhildar avatar Mar 19 '24 13:03 steinnhildar

+1

einarmanif avatar Mar 19 '24 13:03 einarmanif

+1

thebingi avatar Mar 19 '24 13:03 thebingi

Folks, please use :+1: emojis rather than spamming notifications by adding comments. I promise we do consider them when prioritizing features.

tgross avatar Mar 19 '24 14:03 tgross