Auto Generate the HCL2 code of a plugin - packer-plugin-sdk & //go:generate

What are the dependencies required for go generate to generate the HCL2 code for plugins?

I’m working to develop a custom plugin & trying to work with the code generator as described in the hcl guide here but getting errors

Examples show generators implemented with:

//go:generate packer-sdc struct-markdown
//go:generate packer-sdc mapstructure-to-hcl2 -type Config

go generate is giving me errors finding the executables (exec: "packer-sdc": executable file not found in $PATH) and I haven’t managed to find any bin directory or binarys associated with packer-sdc or struct-markdown

Similar unanswered question from 2 years ago

Hi @mlindes,

If you have started your plugin from our scaffolding template project (GitHub - hashicorp/packer-plugin-scaffolding: Quick start repository for creating a Packer plugin.), you should have access to the Makefile that is delivered with it.

If so, invoking make generate will in turn cause the install-packer-sdc target to execute, installing the packer-sdc command through go install.

When that’s done, you should be able to generate the hcl2spec.go files that are required for HCL2 compatibility.

Hope that helps!

Ah. No I did not use that. I’ll check it out.
Looks like that Makefile has the key line


Also important is to add the go/bin directory to my path… there may be a few - like:

export PATH=$PATH:/<user>/go/bin