Using an IDE to guide templates
What would a JSON version of our first template look like? JSON is important because a lot of source material from the community and GitHub is still written in legacy JSON. In fact, JSON has some advantages and disadvantages, so you may want to start with JSON when writing your template and convert it to HCL later. There is no tool within Packer to convert HCL2 to pkr.json
or legacy JSON, so when a JSON option is required, it’s best to start with pkr.json
syntax and not legacy JSON. Only legacy JSON to HCL2 templates can be migrated with Packer’s built-in tool. This can be installed from GitHub or via the go
command:
go install github.com/hashicorp/hcl/v2/cmd/hcldec@latest
Schemas are very helpful when building JSON templates. A JSON schema is simply a specialized JSON document that declares the desired format of another JSON document. Schemas are not available from the Packer engineering team, but Community versions are available...