Change to HCL from JSON #6760
-
Hi, Will you change the already existing Packer configurations to be JSON instead of HCL? The reason why I'm asking, is because we're processing the JSON files and change some values of the Packer configuration. What does the roadmap look like in regards of this? Thank you! |
Beta Was this translation helpful? Give feedback.
Replies: 6 comments 15 replies
-
@aleqsss Hello! We have no plans of converting existing configuration, but any new configurations will be provided in the hcl2 format, as we did with Ubuntu 22.04 |
Beta Was this translation helpful? Give feedback.
-
We are also changing parameters in the JSON currently. I've only scratched the surface so far in terms of what we will need to achieve this with hcl2 but it doesn't look like it will be anywhere near as simple... We have strict Azure Policy (as per MS recommendation) so deploying VHD based VMs with public IPs is a no-go for us. |
Beta Was this translation helpful? Give feedback.
-
Below I'll write out some different reflections/angles/approaches/tools and stuff to try. Perhaps it'll benefit someone, perhaps not. python-hcl2 module (or any other parser for that matter):As brought up by @brgsstm the python-hcl2 module. However, as I see it (might be totally wrong) it could be hard to use any "parser" (not only this searlizer to a Python dict) because will they actually preserve all information? Such as comments and ordering of arguments within blocks? Will the parser actually retain that, if so - how? Perhaps for some scenarios (such as this) that's superfluous anyway? Convert HCL2 <---> JSON (optionally back and forth):Possibility to (in a "stable" way) convert HCL2 <---> JSON. Even if there is some reliable implementation of that (which I doubt because of various dilemmas) there would be a lot of conversion going on and potential trouble. One could however just convert it to JSON, do the modifications on it, then just run Packer with that modified JSON template file as an input, without converting it back to HCL2 again. Still, I'd like to keep away from doing that conversion. Override files (terraform only?)Override Files feature of Terraform, haven't read too much about it so don't know if it works/there's an equivalent for Packer. But for Terraform this seems to be a solution for some scenarios where you'd like to override some stuff. hclwritePerhaps the hclwrite GO package could be of use? Package hclwrite deals with the problem of generating HCL configuration and of making specific surgical changes to existing HCL configurations. It operates at a different level of abstraction than the main HCL parser and AST, since details such as the placement of comments and newlines are preserved when unchanged. |
Beta Was this translation helpful? Give feedback.
-
May bien |
Beta Was this translation helpful? Give feedback.
-
There is a module in Powershell which has been released recently |
Beta Was this translation helpful? Give feedback.
-
I actually update the hcl in my build script using Octopus Deploy's HCLParser using powershell:
...
They have the source public for it: https://github.com/OctopusDeploy/HCLParser Which helped me in figuring out how to use the classes accordingly. One caveat I have is that the .ToString() formats in a way that my packer does not like, due to formatting, so I add the following:
This resolves issues with the dynamic variable in the image section for the tags and some new-line issues I saw that the encoding of UTF8 was not resolving. |
Beta Was this translation helpful? Give feedback.
@aleqsss Hello!
We have no plans of converting existing configuration, but any new configurations will be provided in the hcl2 format, as we did with Ubuntu 22.04