55 lines
1.8 KiB
Go
55 lines
1.8 KiB
Go
//go:generate mapstructure-to-hcl2 -type Config,nicConfig,diskConfig,vgaConfig,additionalISOsConfig
|
|
|
|
package proxmoxiso
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
|
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
|
proxmox "github.com/hashicorp/packer/builder/proxmox/common"
|
|
)
|
|
|
|
type Config struct {
|
|
proxmox.Config `mapstructure:",squash"`
|
|
|
|
commonsteps.ISOConfig `mapstructure:",squash"`
|
|
ISOFile string `mapstructure:"iso_file"`
|
|
ISOStoragePool string `mapstructure:"iso_storage_pool"`
|
|
UnmountISO bool `mapstructure:"unmount_iso"`
|
|
shouldUploadISO bool
|
|
}
|
|
|
|
func (c *Config) Prepare(raws ...interface{}) ([]string, []string, error) {
|
|
var errs *packersdk.MultiError
|
|
_, warnings, merrs := c.Config.Prepare(c, raws...)
|
|
if merrs != nil {
|
|
errs = packersdk.MultiErrorAppend(errs, merrs)
|
|
}
|
|
|
|
// Check ISO config
|
|
// Either a pre-uploaded ISO should be referenced in iso_file, OR a URL
|
|
// (possibly to a local file) to an ISO file that will be downloaded and
|
|
// then uploaded to Proxmox.
|
|
if c.ISOFile != "" {
|
|
c.shouldUploadISO = false
|
|
} else {
|
|
isoWarnings, isoErrors := c.ISOConfig.Prepare(&c.Ctx)
|
|
errs = packersdk.MultiErrorAppend(errs, isoErrors...)
|
|
warnings = append(warnings, isoWarnings...)
|
|
c.shouldUploadISO = true
|
|
}
|
|
|
|
if (c.ISOFile == "" && len(c.ISOConfig.ISOUrls) == 0) || (c.ISOFile != "" && len(c.ISOConfig.ISOUrls) != 0) {
|
|
errs = packersdk.MultiErrorAppend(errs, errors.New("either iso_file or iso_url, but not both, must be specified"))
|
|
}
|
|
if len(c.ISOConfig.ISOUrls) != 0 && c.ISOStoragePool == "" {
|
|
errs = packersdk.MultiErrorAppend(errs, errors.New("when specifying iso_url, iso_storage_pool must also be specified"))
|
|
}
|
|
|
|
if errs != nil && len(errs.Errors) > 0 {
|
|
return nil, warnings, errs
|
|
}
|
|
return nil, warnings, nil
|
|
}
|