Implement `templatefile()` in addition to the `file()` function within jobspecs
- Dominant language
- Go
- Stars
- 17k
- Forks
- 2.1k
- Avg merge
- 1d 9h
- Merged PRs (30d)
- 105
Description
### Proposal
Implement Terraform's [`templatefile()`](https://developer.hashicorp.com/terraform/language/functions/templatefile) function for Nomad job specs, or equivalent with support for templating as part of [HCL spec](https://github.com/hashicorp/hcl/blob/main/hclsyntax/spec.md#template-interpolations).
### Use-cases
While Nomad has support for importing whole files as part of the `file()` function, it would be useful to be able to more directly combine it with for example [HCL2 input variables](https://developer.hashicorp.com/nomad/docs/job-specification/hcl2/variables) and/or client attribute. This would reduce the need for using an external file templating tool to generate the jobspec, or in the case of Terraform templating, stacking both `templatefile()` and Nomad variable interpolation on top of each other. I've encountered cases where I've had to write `$$${var}`, first to escape Terraform, then Nomad, then lastly render a file used for templating within the task.
### Attempted Solutions
It is possible to work around this limitation by passing variables to the [`meta`](https://developer.hashicorp.com/nomad/docs/job-specification/meta) block, and then accessing it via `{{ env "NOMAD_META_var" }}`, however it is a messy solution in comparsion to simply passing `${var}` to the file directly, especially if you want to do any more complex operations such as iterating over a list.
* Related issue: https://github.com/hashicorp/nomad/issues/7954
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the linked Terraform templatefile() documentation and the HCL template interpolation specification, then trace Nomad’s existing file() handling in jobspec evaluation. Compare the related issue #7954 and define how variables and client attributes should behave; done means a supported equivalent is implemented with coverage for the requested templating use cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go, terraform
- Domain
- devops, infrastructure
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100