2018-01-24 06:04:39 -05:00
|
|
|
package clone
|
2017-05-09 10:23:57 -04:00
|
|
|
|
|
|
|
import (
|
2018-01-24 06:04:39 -05:00
|
|
|
packerCommon "github.com/hashicorp/packer/common"
|
2017-05-09 10:23:57 -04:00
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2018-01-24 06:04:39 -05:00
|
|
|
"github.com/jetbrains-infra/packer-builder-vsphere/common"
|
2017-05-09 10:23:57 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-01-30 12:25:05 -05:00
|
|
|
packerCommon.PackerConfig `mapstructure:",squash"`
|
|
|
|
common.ConnectConfig `mapstructure:",squash"`
|
|
|
|
common.RunConfig `mapstructure:",squash"`
|
|
|
|
CloneConfig `mapstructure:",squash"`
|
|
|
|
common.HardwareConfig `mapstructure:",squash"`
|
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
|
|
|
common.ShutdownConfig `mapstructure:",squash"`
|
|
|
|
CreateSnapshot bool `mapstructure:"create_snapshot"`
|
|
|
|
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
2018-05-04 18:48:16 -04:00
|
|
|
common.ConfigParamsConfig `mapstructure:",squash"`
|
2017-05-09 10:23:57 -04:00
|
|
|
|
2017-07-01 11:32:16 -04:00
|
|
|
ctx interpolate.Context
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
func NewConfig(raws ...interface{}) (*Config, []string, error) {
|
|
|
|
c := new(Config)
|
2018-01-24 09:56:14 -05:00
|
|
|
if err := common.DecodeConfig(c, &c.ctx, raws...); err != nil {
|
|
|
|
return nil, nil, err
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
errs := new(packer.MultiError)
|
2017-08-31 08:05:26 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
|
2017-07-01 20:52:10 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CloneConfig.Prepare()...)
|
2017-07-01 17:50:01 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
2017-07-01 20:06:02 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
|
2017-06-13 07:11:41 -04:00
|
|
|
|
2017-05-09 10:23:57 -04:00
|
|
|
if len(errs.Errors) > 0 {
|
2017-07-01 20:52:10 -04:00
|
|
|
return nil, nil, errs
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
2017-07-01 20:52:10 -04:00
|
|
|
return c, nil, nil
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|