packer-cn/builder/vsphere/common/step_config_params.go

39 lines
1.0 KiB
Go
Raw Normal View History

//go:generate struct-markdown
//go:generate mapstructure-to-hcl2 -type ConfigParamsConfig
package common
2018-02-27 00:18:06 +03:00
import (
2018-11-01 00:42:24 +03:00
"context"
"fmt"
"github.com/hashicorp/packer/builder/vsphere/driver"
2018-11-01 00:42:24 +03:00
"github.com/hashicorp/packer/helper/multistep"
2018-02-27 00:18:06 +03:00
"github.com/hashicorp/packer/packer"
)
type ConfigParamsConfig struct {
// Custom parameters.
2018-02-27 00:18:06 +03:00
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
}
type StepConfigParams struct {
Config *ConfigParamsConfig
}
2018-04-25 14:22:38 +03:00
func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
2018-02-27 00:18:06 +03:00
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*driver.VirtualMachine)
2018-05-07 00:26:04 +03:00
if s.Config.ConfigParams != nil {
ui.Say("Adding configuration parameters...")
if err := vm.AddConfigParams(s.Config.ConfigParams); err != nil {
state.Put("error", fmt.Errorf("error adding configuration parameters: %v", err))
return multistep.ActionHalt
}
2018-02-27 00:18:06 +03:00
}
return multistep.ActionContinue
}
func (s *StepConfigParams) Cleanup(state multistep.StateBag) {}