From f3a9e41d3250c0c52b2d1b0e35b2a7a7cce20aa6 Mon Sep 17 00:00:00 2001 From: Coleman McFarland Date: Thu, 2 Apr 2020 20:10:57 -0400 Subject: [PATCH] Upgrade to Packer 1.5 The `Provisioner` interface has changed to accommodate a migration of Packer configs to HCL2. We've run the Hashicorp-provided code generator and checked in the resulting code, and updated the interface. --- bolt/provisioner.go | 8 ++++- bolt/provisioner.hcl2spec.go | 70 ++++++++++++++++++++++++++++++++++++ 2 files changed, 77 insertions(+), 1 deletion(-) create mode 100644 bolt/provisioner.hcl2spec.go diff --git a/bolt/provisioner.go b/bolt/provisioner.go index c456ace..ea19731 100644 --- a/bolt/provisioner.go +++ b/bolt/provisioner.go @@ -1,3 +1,4 @@ +//go:generate mapstructure-to-hcl2 -type Config package bolt import ( @@ -24,6 +25,7 @@ import ( "sync" "unicode" + "github.com/hashicorp/hcl/v2/hcldec" "github.com/hashicorp/packer/common" "github.com/hashicorp/packer/common/adapter" commonhelper "github.com/hashicorp/packer/helper/common" @@ -85,6 +87,10 @@ type PassthroughTemplate struct { WinRMPassword string } +func (p *Provisioner) ConfigSpec() hcldec.ObjectSpec { + return p.config.FlatMapstructure().HCL2Spec() +} + // Prepare the config data for provisioning func (p *Provisioner) Prepare(raws ...interface{}) error { p.done = make(chan struct{}) @@ -185,7 +191,7 @@ func (p *Provisioner) getVersion() error { } // Provision using the Puppet Bolt provisioner -func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator) error { +func (p *Provisioner) Provision(ctx context.Context, ui packer.Ui, comm packer.Communicator, generatedData map[string]interface{}) error { ui.Say("Provisioning with Puppet Bolt...") k, err := newUserKey(p.config.SSHAuthorizedKeyFile) diff --git a/bolt/provisioner.hcl2spec.go b/bolt/provisioner.hcl2spec.go new file mode 100644 index 0000000..4aad4cf --- /dev/null +++ b/bolt/provisioner.hcl2spec.go @@ -0,0 +1,70 @@ +// Code generated by "mapstructure-to-hcl2 -type Config"; DO NOT EDIT. +package bolt + +import ( + "github.com/hashicorp/hcl/v2/hcldec" + "github.com/zclconf/go-cty/cty" +) + +// FlatConfig is an auto-generated flat version of Config. +// Where the contents of a field with a `mapstructure:,squash` tag are bubbled up. +type FlatConfig struct { + PackerBuildName *string `mapstructure:"packer_build_name" cty:"packer_build_name"` + PackerBuilderType *string `mapstructure:"packer_builder_type" cty:"packer_builder_type"` + PackerDebug *bool `mapstructure:"packer_debug" cty:"packer_debug"` + PackerForce *bool `mapstructure:"packer_force" cty:"packer_force"` + PackerOnError *string `mapstructure:"packer_on_error" cty:"packer_on_error"` + PackerUserVars map[string]string `mapstructure:"packer_user_variables" cty:"packer_user_variables"` + PackerSensitiveVars []string `mapstructure:"packer_sensitive_variables" cty:"packer_sensitive_variables"` + Command *string `cty:"command"` + ExtraArguments []string `mapstructure:"extra_arguments" cty:"extra_arguments"` + BoltEnvVars []string `mapstructure:"bolt_env_vars" cty:"bolt_env_vars"` + BoltParams map[interface{}]interface{} `mapstructure:"bolt_params" cty:"bolt_params"` + BoltTask *string `mapstructure:"bolt_task" cty:"bolt_task"` + BoltPlan *string `mapstructure:"bolt_plan" cty:"bolt_plan"` + BoltModulePath *string `mapstructure:"bolt_module_path" cty:"bolt_module_path"` + InventoryFile *string `mapstructure:"inventory_file" cty:"inventory_file"` + LocalPort *int `mapstructure:"local_port" cty:"local_port"` + SkipVersionCheck *bool `mapstructure:"skip_version_check" cty:"skip_version_check"` + User *string `mapstructure:"user" cty:"user"` + SSHHostKeyFile *string `mapstructure:"ssh_host_key_file" cty:"ssh_host_key_file"` + SSHAuthorizedKeyFile *string `mapstructure:"ssh_authorized_key_file" cty:"ssh_authorized_key_file"` + WinRMSSLVerify *bool `mapstructure:"winrm_ssl_verify" cty:"winrm_ssl_verify"` +} + +// FlatMapstructure returns a new FlatConfig. +// FlatConfig is an auto-generated flat version of Config. +// Where the contents a fields with a `mapstructure:,squash` tag are bubbled up. +func (*Config) FlatMapstructure() interface{ HCL2Spec() map[string]hcldec.Spec } { + return new(FlatConfig) +} + +// HCL2Spec returns the hcl spec of a Config. +// This spec is used by HCL to read the fields of Config. +// The decoded values from this spec will then be applied to a FlatConfig. +func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { + s := map[string]hcldec.Spec{ + "packer_build_name": &hcldec.AttrSpec{Name: "packer_build_name", Type: cty.String, Required: false}, + "packer_builder_type": &hcldec.AttrSpec{Name: "packer_builder_type", Type: cty.String, Required: false}, + "packer_debug": &hcldec.AttrSpec{Name: "packer_debug", Type: cty.Bool, Required: false}, + "packer_force": &hcldec.AttrSpec{Name: "packer_force", Type: cty.Bool, Required: false}, + "packer_on_error": &hcldec.AttrSpec{Name: "packer_on_error", Type: cty.String, Required: false}, + "packer_user_variables": &hcldec.BlockAttrsSpec{TypeName: "packer_user_variables", ElementType: cty.String, Required: false}, + "packer_sensitive_variables": &hcldec.AttrSpec{Name: "packer_sensitive_variables", Type: cty.List(cty.String), Required: false}, + "command": &hcldec.AttrSpec{Name: "command", Type: cty.String, Required: false}, + "extra_arguments": &hcldec.AttrSpec{Name: "extra_arguments", Type: cty.List(cty.String), Required: false}, + "bolt_env_vars": &hcldec.AttrSpec{Name: "bolt_env_vars", Type: cty.List(cty.String), Required: false}, + "bolt_params": &hcldec.BlockAttrsSpec{TypeName: "bolt_params", ElementType: cty.String, Required: false}, + "bolt_task": &hcldec.AttrSpec{Name: "bolt_task", Type: cty.String, Required: false}, + "bolt_plan": &hcldec.AttrSpec{Name: "bolt_plan", Type: cty.String, Required: false}, + "bolt_module_path": &hcldec.AttrSpec{Name: "bolt_module_path", Type: cty.String, Required: false}, + "inventory_file": &hcldec.AttrSpec{Name: "inventory_file", Type: cty.String, Required: false}, + "local_port": &hcldec.AttrSpec{Name: "local_port", Type: cty.Number, Required: false}, + "skip_version_check": &hcldec.AttrSpec{Name: "skip_version_check", Type: cty.Bool, Required: false}, + "user": &hcldec.AttrSpec{Name: "user", Type: cty.String, Required: false}, + "ssh_host_key_file": &hcldec.AttrSpec{Name: "ssh_host_key_file", Type: cty.String, Required: false}, + "ssh_authorized_key_file": &hcldec.AttrSpec{Name: "ssh_authorized_key_file", Type: cty.String, Required: false}, + "winrm_ssl_verify": &hcldec.AttrSpec{Name: "winrm_ssl_verify", Type: cty.Bool, Required: false}, + } + return s +}