HCL2: Support user defined blocks and importing other files
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
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:
```hcl
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
```hcl
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.
Contributor guide
No contributing guide indexed for this repository
Research direction
The issue names no files, tests, or concrete entry point. First locate Nomad's HCL2 job parser and its configuration tests, then clarify whether the scope is external-file inclusion or user-defined modules and what variable, local-scope, and import behavior must be covered.
Written by the indexing model from the issue text.
Assessment
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 20/100