packer-cn/common/step_config_params.go

35 lines
920 B
Go
Raw Normal View History

package common
2018-02-26 16:18:06 -05:00
import (
2018-10-31 17:42:24 -04:00
"context"
"fmt"
"github.com/hashicorp/packer/helper/multistep"
2018-02-26 16:18:06 -05:00
"github.com/hashicorp/packer/packer"
"github.com/jetbrains-infra/packer-builder-vsphere/driver"
)
type ConfigParamsConfig struct {
ConfigParams map[string]string `mapstructure:"configuration_parameters"`
}
type StepConfigParams struct {
Config *ConfigParamsConfig
}
2018-04-25 07:22:38 -04:00
func (s *StepConfigParams) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
2018-02-26 16:18:06 -05:00
ui := state.Get("ui").(packer.Ui)
vm := state.Get("vm").(*driver.VirtualMachine)
2018-05-06 17:26:04 -04: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-26 16:18:06 -05:00
}
return multistep.ActionContinue
}
func (s *StepConfigParams) Cleanup(state multistep.StateBag) {}