2020-01-07 19:59:31 -05:00
|
|
|
//go:generate struct-markdown
|
2020-01-08 13:22:55 -05:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
2020-01-07 19:59:31 -05:00
|
|
|
|
2018-01-24 06:04:39 -05:00
|
|
|
package clone
|
2017-05-09 10:23:57 -04:00
|
|
|
|
|
|
|
import (
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/common"
|
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"
|
2018-10-31 17:42:24 -04:00
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2017-05-09 10:23:57 -04:00
|
|
|
"github.com/hashicorp/packer/packer"
|
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-05-06 17:26:04 -04:00
|
|
|
packerCommon.PackerConfig `mapstructure:",squash"`
|
|
|
|
|
|
|
|
common.ConnectConfig `mapstructure:",squash"`
|
|
|
|
CloneConfig `mapstructure:",squash"`
|
|
|
|
common.LocationConfig `mapstructure:",squash"`
|
|
|
|
common.HardwareConfig `mapstructure:",squash"`
|
|
|
|
common.ConfigParamsConfig `mapstructure:",squash"`
|
|
|
|
|
2018-10-31 17:42:24 -04:00
|
|
|
common.RunConfig `mapstructure:",squash"`
|
2018-05-30 07:52:27 -04:00
|
|
|
common.WaitIpConfig `mapstructure:",squash"`
|
2018-10-31 17:42:24 -04:00
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
|
|
|
common.ShutdownConfig `mapstructure:",squash"`
|
2018-05-06 17:26:04 -04:00
|
|
|
|
2020-01-07 19:59:31 -05:00
|
|
|
// Create a snapshot when set to `true`, so the VM can be used as a base
|
|
|
|
// for linked clones. Defaults to `false`.
|
|
|
|
CreateSnapshot bool `mapstructure:"create_snapshot"`
|
|
|
|
// Convert VM to a template. Defaults to `false`.
|
2018-05-06 17:26:04 -04:00
|
|
|
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
2017-05-09 10:23:57 -04:00
|
|
|
|
2020-03-19 13:51:43 -04:00
|
|
|
Export *common.ExportConfig `mapstructure:"export"`
|
|
|
|
|
2017-07-01 11:32:16 -04:00
|
|
|
ctx interpolate.Context
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
2020-01-13 15:33:56 -05:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2018-05-06 17:26:04 -04:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
2020-01-13 15:33:56 -05:00
|
|
|
return nil, err
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
errs := new(packer.MultiError)
|
2017-07-01 20:52:10 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CloneConfig.Prepare()...)
|
2018-05-06 17:26:04 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.LocationConfig.Prepare()...)
|
2017-07-01 17:50:01 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
2018-05-06 17:26:04 -04:00
|
|
|
|
2018-05-30 07:52:27 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.WaitIpConfig.Prepare()...)
|
2018-05-06 17:26:04 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
|
2017-07-01 20:06:02 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ShutdownConfig.Prepare()...)
|
2020-03-19 13:51:43 -04:00
|
|
|
if c.Export != nil {
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.Export.Prepare(&c.ctx, &c.LocationConfig, &c.PackerConfig)...)
|
|
|
|
}
|
2017-06-13 07:11:41 -04:00
|
|
|
|
2017-05-09 10:23:57 -04:00
|
|
|
if len(errs.Errors) > 0 {
|
2020-01-13 15:33:56 -05:00
|
|
|
return nil, errs
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|
|
|
|
|
2020-01-13 15:33:56 -05:00
|
|
|
return nil, nil
|
2017-05-09 10:23:57 -04:00
|
|
|
}
|