Converting Nomad Job Spec HCL to JSON and Back?
- Dominant language
- Go
- Stars
- 5.8k
- Forks
- 657
- Avg merge
- 20h 36m
- Merged PRs (30d)
- 6
Description
It has been very difficult to prop up some basic tooling around HCL based config files.
There are multiple projects that try to help with this issue but I have not been able to find one to do this correctly for my use case. I am hoping somebody might be able to point me in the right direction.
I have tried:
### 1. Using the `nomad` cli.
This would be the ideal way except for a few things.
- It wants to know the values of vars ahead of time so it can interpolate them. I need to keep the variable names and ${} syntax in place.
- There seems to be no way to go back to HCL once we have the JSON
### 2. Using a tool like https://github.com/hashicorp/hcl/tree/main/cmd/hcldec
This would also be ideal, but one big exception:
- It requires the creation of a spec of its own to compile down to the correct 'flavor' of HCL in JSON format. (I think?)
- I could not find any official specs for HashiCorp HCL flavors like Nomad/Terraform and I imagine it would be an effort for me to take on myself. https://hcl.readthedocs.io/en/latest/go_decoding_hcldec.html
### 3. Using third party tools like https://github.com/tmccombs/hcl2json.
This particular ones seems to work well...almost.
- It leaves my variables and their related syntax alone so that is a +1.
- It does not quite generate the right JSON format for Nomad specs. Ex. Constraints, Templates (which are key for me)
- There is no way to go back to HCL after
### 4. Another third party tool - https://github.com/kvz/json2hcl.
- This one can go to from JSON to HCL and reverse.
- Does not support HCL2 (dealbreaker)
After digging into the code a little I found https://github.com/hashicorp/nomad/blob/main/jobspec/parse_job.go but could not find where it runs or how I might be able to use it.
Does anybody have any advice? Or has taken a stab at writing a Nomad `hcldec` spec file? Does `hcldec` do the reverse conversion?
Thanks
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading jobspec/parse_job.go and the linked hcldec and third-party conversion tools. Determine whether HCL2 conversion can preserve variable expressions and Nomad constraints/templates in both directions; done would require a clear supported approach or defined implementation scope.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100