From 8c219166068cfa8de3af5ec6c88dfd21270ececb Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:01:48 +0100 Subject: [PATCH 01/22] add guide on how to make ones component HCL2 enabled --- .../component-object-spec/index.html.mr.erb | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 website/source/guides/hcl/component-object-spec/index.html.mr.erb diff --git a/website/source/guides/hcl/component-object-spec/index.html.mr.erb b/website/source/guides/hcl/component-object-spec/index.html.mr.erb new file mode 100644 index 000000000..68ebe0178 --- /dev/null +++ b/website/source/guides/hcl/component-object-spec/index.html.mr.erb @@ -0,0 +1,37 @@ +--- +layout: guides +page_title: Generating code for congig spec. +sidebar_current: hcl +description: |- + Learn how to generate the HCL2 configuration of your component easily. +--- + +# Packer 1.5.0 can be + +From version 1.5.0 Packer can be configured using HCL2. Because Packer has so +many builders, provisioner & post-proessors, we relied on code generation to +iterate more easily. The good new is that you can benefit from this code +generator to get the HCL2 spec of your component simply. Is it a Go binary +package and is located in `cmd/mapstructure-to-hcl2`. Here are some simple +steps you can follow to have most of the code required : + +Say you want to configure the Config struct of a Builder in a package located +in `my/example-plugin/config.go`. + +* run `go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2` + +* Add `//go:generate mapstructure-to-hcl2 -type Config` at the top of +`config.go` + +* run `go generate my/example-plugin` + +This will generate a `my/example-plugin/config.hcl2spec.go` file containing the +configuration fields of Config. Now we only need to make Builder implement the +interface by adding the following snippet: + +```go +func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } +``` + +From now one every time you add or change a field of Config you will need to +run he `go generate` command again. From 1ada06b2d75228a9f1080989358a4c57913c8d59 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:22:48 +0100 Subject: [PATCH 02/22] fix sidebar_current of guide/hcl/from-json-v1 --- website/source/guides/hcl/from-json-v1/index.html.md.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/guides/hcl/from-json-v1/index.html.md.erb b/website/source/guides/hcl/from-json-v1/index.html.md.erb index 07ccdbf2b..e3917c52d 100644 --- a/website/source/guides/hcl/from-json-v1/index.html.md.erb +++ b/website/source/guides/hcl/from-json-v1/index.html.md.erb @@ -1,7 +1,7 @@ --- layout: guides page_title: Transforming Packer v1 files for Packer v1.5.0 -sidebar_current: hcl +sidebar_current: hcl-from-json-v1 description: |- Learn how to manually move from a Packer v1 working JSON build file to a working v1.5.0 HCL file. From da90c22c35f0bdd47f4a929bfbca3f8cda457620 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:51:13 +0100 Subject: [PATCH 03/22] Update index.html.md.erb better title --- website/source/guides/hcl/from-json-v1/index.html.md.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/guides/hcl/from-json-v1/index.html.md.erb b/website/source/guides/hcl/from-json-v1/index.html.md.erb index e3917c52d..4c62edf47 100644 --- a/website/source/guides/hcl/from-json-v1/index.html.md.erb +++ b/website/source/guides/hcl/from-json-v1/index.html.md.erb @@ -7,7 +7,7 @@ description: |- working v1.5.0 HCL file. --- -# Transforming Packer v1 files for Packer v1.5 +# Transforming Packer v1 config files for Packer v1.5 -> **Note:** Starting from version **1.5.0** Packer can read HCL2 files. From 93b9f3cb80ff719842bba46a077394d864de3e41 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:51:32 +0100 Subject: [PATCH 04/22] rename --- .../component-object-spec/index.html.md.erb | 41 +++++++++++++++++++ .../component-object-spec/index.html.mr.erb | 37 ----------------- 2 files changed, 41 insertions(+), 37 deletions(-) create mode 100644 website/source/guides/hcl/component-object-spec/index.html.md.erb delete mode 100644 website/source/guides/hcl/component-object-spec/index.html.mr.erb diff --git a/website/source/guides/hcl/component-object-spec/index.html.md.erb b/website/source/guides/hcl/component-object-spec/index.html.md.erb new file mode 100644 index 000000000..e1acbcbe6 --- /dev/null +++ b/website/source/guides/hcl/component-object-spec/index.html.md.erb @@ -0,0 +1,41 @@ +--- +layout: guides +page_title: Generating code for congig spec. +sidebar_current: hcl +description: |- + Learn how to generate the HCL2 configuration of your component easily. +--- + +# Auto Generate the HCL2 code of a plugin + +From version 1.5.0 Packer can be configured using HCL2. Because Packer has so +many builders, provisioner & post-proessors, we relied on code generation to +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 +package and is located in `cmd/mapstructure-to-hcl2`. + +Say you want to configure the Config struct of a Builder in a package located +in `my/example-plugin/config.go`. Here are some simple steps you can follow to +have most of the code generated: + +* run `go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2` + +* Add `//go:generate mapstructure-to-hcl2 -type Config` at the top of +`config.go` + +* run `go generate my/example-plugin` + + This will generate a `my/example-plugin/config.hcl2spec.go` file containing + the configuration fields of Config. + +* Make sure that all the nested fields of Config are auto generated the same way. + +* Now we only need to make Builder implement the interface by adding the +following snippet: + + ```go + func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } + ``` + + From now one every time you add or change a field of Config you will need to + run he `go generate` command again. diff --git a/website/source/guides/hcl/component-object-spec/index.html.mr.erb b/website/source/guides/hcl/component-object-spec/index.html.mr.erb deleted file mode 100644 index 68ebe0178..000000000 --- a/website/source/guides/hcl/component-object-spec/index.html.mr.erb +++ /dev/null @@ -1,37 +0,0 @@ ---- -layout: guides -page_title: Generating code for congig spec. -sidebar_current: hcl -description: |- - Learn how to generate the HCL2 configuration of your component easily. ---- - -# Packer 1.5.0 can be - -From version 1.5.0 Packer can be configured using HCL2. Because Packer has so -many builders, provisioner & post-proessors, we relied on code generation to -iterate more easily. The good new is that you can benefit from this code -generator to get the HCL2 spec of your component simply. Is it a Go binary -package and is located in `cmd/mapstructure-to-hcl2`. Here are some simple -steps you can follow to have most of the code required : - -Say you want to configure the Config struct of a Builder in a package located -in `my/example-plugin/config.go`. - -* run `go install github.com/hashicorp/packer/cmd/mapstructure-to-hcl2` - -* Add `//go:generate mapstructure-to-hcl2 -type Config` at the top of -`config.go` - -* run `go generate my/example-plugin` - -This will generate a `my/example-plugin/config.hcl2spec.go` file containing the -configuration fields of Config. Now we only need to make Builder implement the -interface by adding the following snippet: - -```go -func (b *Builder) ConfigSpec() hcldec.ObjectSpec { return b.config.FlatMapstructure().HCL2Spec() } -``` - -From now one every time you add or change a field of Config you will need to -run he `go generate` command again. From 8dc587967ecd1ae75b42906b96da0dd466e337e1 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:51:38 +0100 Subject: [PATCH 05/22] Update guides.erb --- website/source/layouts/guides.erb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/website/source/layouts/guides.erb b/website/source/layouts/guides.erb index 7d9859a39..32c081f82 100644 --- a/website/source/layouts/guides.erb +++ b/website/source/layouts/guides.erb @@ -7,6 +7,9 @@ > from JSON v1 + > + Making a plugin HCL2 enabled + > From f3629dbaf78057d2e0df3b3d06fde0c7ae944d46 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:57:01 +0100 Subject: [PATCH 06/22] Update index.html.md.erb fix sidebar_current --- .../source/guides/hcl/component-object-spec/index.html.md.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/source/guides/hcl/component-object-spec/index.html.md.erb b/website/source/guides/hcl/component-object-spec/index.html.md.erb index e1acbcbe6..7be4178b0 100644 --- a/website/source/guides/hcl/component-object-spec/index.html.md.erb +++ b/website/source/guides/hcl/component-object-spec/index.html.md.erb @@ -1,7 +1,7 @@ --- layout: guides page_title: Generating code for congig spec. -sidebar_current: hcl +sidebar_current: hcl-component-object-spec description: |- Learn how to generate the HCL2 configuration of your component easily. --- From 9219a606a320f04b7c40b452209cd0d039424e36 Mon Sep 17 00:00:00 2001 From: Adrien Delorme Date: Wed, 18 Dec 2019 15:57:28 +0100 Subject: [PATCH 07/22] move "Installing Packer" a little lower in the nav bar --- website/source/layouts/docs.erb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/website/source/layouts/docs.erb b/website/source/layouts/docs.erb index c6f13a3e3..657ed4867 100644 --- a/website/source/layouts/docs.erb +++ b/website/source/layouts/docs.erb @@ -1,9 +1,7 @@ <% wrap_layout :inner do %> <% content_for :sidebar do %>