nomad
nomad copied to clipboard
HCL2: Support user defined blocks and importing other files
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.
linking to https://github.com/hashicorp/nomad/issues/7954
and linking to prior art: https://pkg.go.dev/github.com/hashicorp/hcl2/ext/include
Looking for this as well
Add one more vote for this.
Another vote for this
Another vote for this
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
another vote for this
Another vote.
Definite vote for this 👍
Another vote
Vote for this
+1 vote
+1
+1
Folks, please use :+1: emojis rather than spamming notifications by adding comments. I promise we do consider them when prioritizing features.