2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2013-12-22 13:40:39 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
2015-05-27 17:01:08 -04:00
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-22 13:40:39 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
type ExportConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// Either ovf or ova, this specifies the output format
|
2019-06-06 10:29:25 -04:00
|
|
|
// of the exported virtual machine. This defaults to ovf.
|
2019-05-28 11:50:58 -04:00
|
|
|
Format string `mapstructure:"format" required:"false"`
|
2019-06-19 10:34:14 -04:00
|
|
|
// Additional options to pass to the [VBoxManage
|
|
|
|
// export](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export).
|
|
|
|
// This can be useful for passing product information to include in the
|
|
|
|
// resulting appliance file. Packer JSON configuration file example:
|
|
|
|
//
|
2020-08-20 09:43:38 -04:00
|
|
|
// In JSON:
|
2020-03-12 10:05:08 -04:00
|
|
|
// ```json
|
2019-06-19 10:34:14 -04:00
|
|
|
// {
|
|
|
|
// "type": "virtualbox-iso",
|
|
|
|
// "export_opts":
|
|
|
|
// [
|
|
|
|
// "--manifest",
|
|
|
|
// "--vsys", "0",
|
|
|
|
// "--description", "{{user `vm_description`}}",
|
|
|
|
// "--version", "{{user `vm_version`}}"
|
|
|
|
// ],
|
|
|
|
// "format": "ova",
|
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
//
|
2020-08-20 09:43:38 -04:00
|
|
|
// In HCL2:
|
|
|
|
// ```hcl
|
|
|
|
// source "virtualbox-iso" "basic-example" {
|
|
|
|
// export_opts = [
|
|
|
|
// "--manifest",
|
|
|
|
// "--vsys", "0",
|
|
|
|
// "--description", "{{user `vm_description`}}",
|
|
|
|
// "--version", "{{user `vm_version`}}"
|
|
|
|
// ]
|
|
|
|
// format = "ova"
|
|
|
|
// }
|
|
|
|
// ```
|
|
|
|
//
|
2019-06-19 10:34:14 -04:00
|
|
|
// A VirtualBox [VM
|
|
|
|
// description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf)
|
|
|
|
// may contain arbitrary strings; the GUI interprets HTML formatting. However,
|
|
|
|
// the JSON format does not allow arbitrary newlines within a value. Add a
|
|
|
|
// multi-line description by preparing the string in the shell before the
|
|
|
|
// packer call like this (shell `>` continuation character snipped for easier
|
|
|
|
// copy & paste):
|
|
|
|
//
|
2020-05-29 17:22:16 -04:00
|
|
|
// ```shell
|
2019-06-19 10:34:14 -04:00
|
|
|
// vm_description='some
|
|
|
|
// multiline
|
|
|
|
// description'
|
|
|
|
//
|
|
|
|
// vm_version='0.2.0'
|
|
|
|
//
|
|
|
|
// packer build \
|
|
|
|
// -var "vm_description=${vm_description}" \
|
|
|
|
// -var "vm_version=${vm_version}" \
|
|
|
|
// "packer_conf.json"
|
|
|
|
// ```
|
|
|
|
ExportOpts []string `mapstructure:"export_opts" required:"false"`
|
2013-12-22 13:40:39 -05:00
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
func (c *ExportConfig) Prepare(ctx *interpolate.Context) []error {
|
2013-12-22 13:40:39 -05:00
|
|
|
if c.Format == "" {
|
|
|
|
c.Format = "ovf"
|
|
|
|
}
|
|
|
|
|
2015-05-27 17:01:08 -04:00
|
|
|
var errs []error
|
2013-12-22 13:40:39 -05:00
|
|
|
if c.Format != "ovf" && c.Format != "ova" {
|
|
|
|
errs = append(errs,
|
|
|
|
errors.New("invalid format, only 'ovf' or 'ova' are allowed"))
|
|
|
|
}
|
|
|
|
|
2019-06-19 10:34:14 -04:00
|
|
|
if c.ExportOpts == nil {
|
|
|
|
c.ExportOpts = make([]string, 0)
|
|
|
|
}
|
|
|
|
|
2013-12-22 13:40:39 -05:00
|
|
|
return errs
|
|
|
|
}
|