2020-03-05 15:04:15 -05:00
|
|
|
//go:generate struct-markdown
|
2020-01-08 13:22:55 -05:00
|
|
|
//go:generate mapstructure-to-hcl2 -type Config
|
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
package iso
|
|
|
|
|
|
|
|
import (
|
2020-12-17 16:29:25 -05:00
|
|
|
packerCommon "github.com/hashicorp/packer-plugin-sdk/common"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/communicator"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
|
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/config"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
2020-01-07 19:59:31 -05:00
|
|
|
"github.com/hashicorp/packer/builder/vsphere/common"
|
2018-01-24 09:56:14 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type Config struct {
|
2018-05-06 17:26:04 -04:00
|
|
|
packerCommon.PackerConfig `mapstructure:",squash"`
|
2020-11-11 18:04:28 -05:00
|
|
|
commonsteps.HTTPConfig `mapstructure:",squash"`
|
|
|
|
commonsteps.CDConfig `mapstructure:",squash"`
|
2018-01-24 09:56:14 -05:00
|
|
|
|
2018-05-06 17:26:04 -04:00
|
|
|
common.ConnectConfig `mapstructure:",squash"`
|
2018-05-04 18:48:16 -04:00
|
|
|
CreateConfig `mapstructure:",squash"`
|
2018-05-06 17:26:04 -04:00
|
|
|
common.LocationConfig `mapstructure:",squash"`
|
2018-05-05 17:41:14 -04:00
|
|
|
common.HardwareConfig `mapstructure:",squash"`
|
2018-05-04 18:48:16 -04:00
|
|
|
common.ConfigParamsConfig `mapstructure:",squash"`
|
2018-01-24 09:56:14 -05:00
|
|
|
|
2020-11-11 18:04:28 -05:00
|
|
|
commonsteps.ISOConfig `mapstructure:",squash"`
|
2019-01-04 09:07:09 -05:00
|
|
|
|
2020-09-22 05:32:25 -04:00
|
|
|
common.CDRomConfig `mapstructure:",squash"`
|
2020-09-18 11:09:01 -04: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"`
|
2019-01-04 09:07:09 -05:00
|
|
|
|
2018-10-31 17:42:24 -04:00
|
|
|
common.ShutdownConfig `mapstructure:",squash"`
|
2018-05-06 17:26:04 -04:00
|
|
|
|
2020-03-05 15:04:15 -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"`
|
2020-03-19 13:51:43 -04:00
|
|
|
// Configuration for exporting VM to an ovf file.
|
|
|
|
// The VM will not be exported if no [Export Configuration](#export-configuration) is specified.
|
|
|
|
Export *common.ExportConfig `mapstructure:"export"`
|
2020-07-10 05:01:10 -04:00
|
|
|
// Configuration for importing the VM template to a Content Library.
|
|
|
|
// The VM template will not be imported if no [Content Library Import Configuration](#content-library-import-configuration) is specified.
|
|
|
|
// The import doesn't work if [convert_to_template](#convert_to_template) is set to true.
|
|
|
|
ContentLibraryDestinationConfig *common.ContentLibraryDestinationConfig `mapstructure:"content_library_destination"`
|
2018-05-06 17:26:04 -04:00
|
|
|
|
2018-01-24 09:56:14 -05:00
|
|
|
ctx interpolate.Context
|
|
|
|
}
|
|
|
|
|
2020-01-13 14:51:36 -05:00
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
|
2018-05-06 17:26:04 -04:00
|
|
|
err := config.Decode(c, &config.DecodeOpts{
|
2020-10-09 20:01:55 -04:00
|
|
|
PluginType: common.BuilderId,
|
2018-05-06 17:26:04 -04:00
|
|
|
Interpolate: true,
|
|
|
|
InterpolateContext: &c.ctx,
|
2018-12-22 18:13:31 -05:00
|
|
|
InterpolateFilter: &interpolate.RenderFilter{
|
|
|
|
Exclude: []string{
|
|
|
|
"boot_command",
|
|
|
|
},
|
|
|
|
},
|
2018-05-06 17:26:04 -04:00
|
|
|
}, raws...)
|
|
|
|
if err != nil {
|
2020-01-13 14:51:36 -05:00
|
|
|
return nil, err
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
2019-01-04 09:07:09 -05:00
|
|
|
warnings := make([]string, 0)
|
2020-11-19 15:07:02 -05:00
|
|
|
errs := new(packersdk.MultiError)
|
2019-01-04 09:07:09 -05:00
|
|
|
|
2020-06-01 15:27:26 -04:00
|
|
|
if c.ISOUrls != nil || c.RawSingleISOUrl != "" {
|
|
|
|
isoWarnings, isoErrs := c.ISOConfig.Prepare(&c.ctx)
|
|
|
|
warnings = append(warnings, isoWarnings...)
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, isoErrs...)
|
2020-06-01 15:27:26 -04:00
|
|
|
}
|
2019-01-04 09:07:09 -05:00
|
|
|
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.ConnectConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.CreateConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.LocationConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.HardwareConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.HTTPConfig.Prepare(&c.ctx)...)
|
2018-05-06 17:26:04 -04:00
|
|
|
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.CDRomConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.CDConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.BootConfig.Prepare(&c.ctx)...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.WaitIpConfig.Prepare()...)
|
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.Comm.Prepare(&c.ctx)...)
|
2020-10-13 15:12:28 -04:00
|
|
|
|
|
|
|
shutdownWarnings, shutdownErrs := c.ShutdownConfig.Prepare(c.Comm)
|
|
|
|
warnings = append(warnings, shutdownWarnings...)
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, shutdownErrs...)
|
2020-10-13 15:12:28 -04:00
|
|
|
|
2020-03-19 13:51:43 -04:00
|
|
|
if c.Export != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.Export.Prepare(&c.ctx, &c.LocationConfig, &c.PackerConfig)...)
|
2020-03-19 13:51:43 -04:00
|
|
|
}
|
2020-07-10 05:01:10 -04:00
|
|
|
if c.ContentLibraryDestinationConfig != nil {
|
2020-11-19 15:07:02 -05:00
|
|
|
errs = packersdk.MultiErrorAppend(errs, c.ContentLibraryDestinationConfig.Prepare(&c.LocationConfig)...)
|
2020-07-10 05:01:10 -04:00
|
|
|
}
|
2018-01-24 09:56:14 -05:00
|
|
|
|
|
|
|
if len(errs.Errors) > 0 {
|
2020-01-13 18:52:05 -05:00
|
|
|
return warnings, errs
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|
|
|
|
|
2020-01-13 18:52:05 -05:00
|
|
|
return warnings, nil
|
2018-01-24 09:56:14 -05:00
|
|
|
}
|