Update index.html.md.erb

This commit is contained in:
Adrien Delorme 2019-12-19 15:40:08 +01:00
parent 31cad234f2
commit fbd3796377
1 changed files with 13 additions and 10 deletions

View File

@ -8,27 +8,28 @@ description: |-
# Auto Generate the HCL2 code of a plugin # Auto Generate the HCL2 code of a plugin
From version 1.5.0 Packer can be configured using HCL2. Because Packer has so From v1.5, Packer can be configured using HCL2. Because Packer has so many
many builders, provisioner & post-proessors, we relied on code generation to builders, provisioner & post-processors, we relied on code generation to
iterate more easily. The good new is that you can benefit from this code iterate more easily. The good new is that you can benefit from this code
generator to get the HCL2 spec code of your component simply. Is it a Go binary generator to get the HCL2 spec code of your component simply. It's a Go binary
package and is located in `cmd/mapstructure-to-hcl2`. package and is located in [`cmd/mapstructure-to-hcl2`](https://github.com/hashicorp/packer/tree/master/cmd/mapstructure-to-hcl2).
Say you want to configure the Config struct of a Builder in a package located Say you want to configure the `Config` struct of a `Builder` in a package
in `my/example-plugin/config.go`. Here are some simple steps you can follow to located in `my/example-plugin/config.go`. Here are some simple steps you can
have most of the code generated: follow to make it HCL2 enabled:
* run `go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2` * run `go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2`
* Add `//go:generate mapstructure-to-hcl2 -type Config` at the top of * Add `//go:generate mapstructure-to-hcl2 -type Config` at the top of
`config.go` `config.go`
* run `go generate my/example-plugin` * run `go generate ./my/example-plugin/...`
This will generate a `my/example-plugin/config.hcl2spec.go` file containing This will generate a `my/example-plugin/config.hcl2spec.go` file containing
the configuration fields of Config. the configuration fields of `Config`.
* Make sure that all the nested fields of Config are auto generated the same way. * Make sure that all the nested structs of `Config` are also auto generated the
same way.
* Now we only need to make Builder implement the interface by adding the * Now we only need to make Builder implement the interface by adding the
following snippet: following snippet:
@ -39,3 +40,5 @@ following snippet:
From now on every time you add or change a field of Config you will need to From now on every time you add or change a field of Config you will need to
run the `go generate` command again. run the `go generate` command again.
A good example of this is the [Config struct of the amazon-ebs builder](https://github.com/hashicorp/packer/blob/master/builder/amazon/ebs/builder.go)