2020-01-07 16:59:31 -08:00
|
|
|
//go:generate struct-markdown
|
2020-01-08 10:22:55 -08:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
2020-01-07 16:59:31 -08:00
|
|
|
|
2018-01-24 14:04:39 +03:00
|
|
|
package clone
|
2017-05-09 17:23:57 +03:00
|
|
|
|
|
|
|
import (
|
2020-01-07 16:59:31 -08:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/common"
|
2017-05-09 17:23:57 +03:00
|
|
|
"github.com/hashicorp/packer/helper/communicator"
|
2018-11-01 00:42:24 +03:00
|
|
|
"github.com/hashicorp/packer/helper/config"
|
2017-05-09 17:23:57 +03:00
|
|
|
"github.com/hashicorp/packer/packer"
|
2020-11-12 14:44:02 -08:00
|
|
|
packerCommon "github.com/hashicorp/packer/packer-plugin-sdk/common"
|
2020-11-17 16:31:03 -08:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/multistep/commonsteps"
|
2020-11-11 10:21:37 -08:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2017-05-09 17:23:57 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-05-07 00:26:04 +03:00
|
|
|
packerCommon.PackerConfig `mapstructure:",squash"`
|
2020-11-11 15:04:28 -08:00
|
|
|
commonsteps.HTTPConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.CDConfig `mapstructure:",squash"`
|
2018-05-07 00:26:04 +03:00
|
|
|
|
|
|
|
common.ConnectConfig `mapstructure:",squash"`
|
|
|
|
CloneConfig `mapstructure:",squash"`
|
|
|
|
common.LocationConfig `mapstructure:",squash"`
|
|
|
|
common.HardwareConfig `mapstructure:",squash"`
|
|
|
|
common.ConfigParamsConfig `mapstructure:",squash"`
|
|
|
|
|
2020-09-22 11:32:25 +02:00
|
|
|
common.CDRomConfig `mapstructure:",squash"`
|
2020-09-18 17:09:01 +02:00
|
|
|
common.RemoveCDRomConfig `mapstructure:",squash"`
|
|
|
|
common.FloppyConfig `mapstructure:",squash"`
|
|
|
|
common.RunConfig `mapstructure:",squash"`
|
|
|
|
common.BootConfig `mapstructure:",squash"`
|
|
|
|
common.WaitIpConfig `mapstructure:",squash"`
|
|
|
|
Comm communicator.Config `mapstructure:",squash"`
|
|
|
|
common.ShutdownConfig `mapstructure:",squash"`
|
2018-05-07 00:26:04 +03:00
|
|
|
|
2020-01-07 16:59:31 -08: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-07 00:26:04 +03:00
|
|
|
ConvertToTemplate bool `mapstructure:"convert_to_template"`
|
2020-07-10 11:01:10 +02:00
|
|
|
// Configuration for exporting VM to an ovf file.
|
|
|
|
// The VM will not be exported if no [Export Configuration](#export-configuration) is specified.
|
2020-03-19 13:51:43 -04:00
|
|
|
Export *common.ExportConfig `mapstructure:"export"`
|
2020-08-19 13:20:25 +02:00
|
|
|
// Configuration for importing a VM template or OVF template to a Content Library.
|
|
|
|
// The template will not be imported if no [Content Library Import Configuration](#content-library-import-configuration) is specified.
|
2020-07-10 11:01:10 +02:00
|
|
|
// The import doesn't work if [convert_to_template](#convert_to_template) is set to true.
|
|
|
|
ContentLibraryDestinationConfig *common.ContentLibraryDestinationConfig `mapstructure:"content_library_destination"`
|
2020-07-29 09:09:58 +02:00
|
|
|
// Customize the cloned VM to configure host, network, or licensing settings. See the [customization options](#customization).
|
|
|
|
CustomizeConfig *CustomizeConfig `mapstructure:"customize"`
|
2020-03-19 13:51:43 -04:00
|
|
|
|
2017-07-01 18:32:16 +03:00
|
|
|
ctx interpolate.Context
|
2017-05-09 17:23:57 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:33:56 -08:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2018-05-07 00:26:04 +03:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2020-10-09 17:01:55 -07:00
|
|
|
PluginType: common.BuilderId,
|
2018-05-07 00:26:04 +03:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
2020-06-24 11:14:30 +02:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
},
|
|
|
|
},
|
2018-05-07 00:26:04 +03:00
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
2020-01-13 12:33:56 -08:00
|
|
|
return nil, err
|
2017-05-09 17:23:57 +03:00
|
|
|
}
|
|
|
|
|
2020-10-13 16:47:00 -04:00
|
|
|
// warnings := make([]string, 0)
|
2017-05-09 17:23:57 +03:00
|
|
|
errs := new(packer.MultiError)
|
2020-10-13 15:26:32 -04:00
|
|
|
|
2017-07-02 03:52:10 +03:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CloneConfig.Prepare()...)
|
2018-05-07 00:26:04 +03:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.LocationConfig.Prepare()...)
|
2017-07-02 00:50:01 +03:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
2020-06-24 11:14:30 +02:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
|
2018-05-07 00:26:04 +03:00
|
|
|
|
2020-09-18 17:09:01 +02:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.CDRomConfig.Prepare()...)
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
|
2020-06-24 11:14:30 +02:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
2018-05-30 14:52:27 +03:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.WaitIpConfig.Prepare()...)
|
2018-05-07 00:26:04 +03:00
|
|
|
errs = packer.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
|
2020-10-13 15:26:32 -04:00
|
|
|
|
2020-10-13 16:47:00 -04:00
|
|
|
_, shutdownErrs := c.ShutdownConfig.Prepare(c.Comm)
|
|
|
|
// shutdownWarnings, shutdownErrs := c.ShutdownConfig.Prepare(c.Comm)
|
|
|
|
// warnings = append(warnings, shutdownWarnings...)
|
2020-10-13 15:26:32 -04:00
|
|
|
errs = packer.MultiErrorAppend(errs, shutdownErrs...)
|
|
|
|
|
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)...)
|
|
|
|
}
|
2020-07-10 11:01:10 +02:00
|
|
|
if c.ContentLibraryDestinationConfig != nil {
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.ContentLibraryDestinationConfig.Prepare(&c.LocationConfig)...)
|
|
|
|
}
|
2020-07-29 09:09:58 +02:00
|
|
|
if c.CustomizeConfig != nil {
|
|
|
|
errs = packer.MultiErrorAppend(errs, c.CustomizeConfig.Prepare()...)
|
|
|
|
}
|
2017-06-13 14:11:41 +03:00
|
|
|
|
2017-05-09 17:23:57 +03:00
|
|
|
if len(errs.Errors) > 0 {
|
2020-01-13 12:33:56 -08:00
|
|
|
return nil, errs
|
2017-05-09 17:23:57 +03:00
|
|
|
}
|
|
|
|
|
2020-01-13 12:33:56 -08:00
|
|
|
return nil, nil
|
2017-05-09 17:23:57 +03:00
|
|
|
}
|