packer-cn/builder/virtualbox/common/vboxmanage_config.go

61 lines
2.0 KiB
Go
Raw Normal View History

//go:generate struct-markdown
2013-12-22 12:24:29 -05:00
package common
import (
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
2013-12-22 12:24:29 -05:00
)
//In order to perform extra customization of the virtual machine, a template can
//define extra calls to `VBoxManage` to perform.
//[VBoxManage](https://www.virtualbox.org/manual/ch09.html) is the command-line
//interface to VirtualBox where you can completely control VirtualBox. It can be
//used to do things such as set RAM, CPUs, etc.
2013-12-22 12:24:29 -05:00
type VBoxManageConfig struct {
2019-06-19 11:07:23 -04:00
// Custom `VBoxManage` commands to execute in order to further customize
// the virtual machine being created. The example shown below sets the memory and number of CPUs
// within the virtual machine:
//
// In JSON:
// ```json
// "vboxmanage": [
// ["modifyvm", "{{.Name}}", "--memory", "1024"],
// ["modifyvm", "{{.Name}}", "--cpus", "2"]
// ]
// ```
//
// In HCL2:
// ```hcl
// vboxmanage = [
// ["modifyvm", "{{.Name}}", "--memory", "1024"],
// ["modifyvm", "{{.Name}}", "--cpus", "2"],
// ]
// ```
//
// The value of `vboxmanage` is an array of commands to execute. These commands are
// executed in the order defined. So in the above example, the memory will be set
// followed by the CPUs.
// Each command itself is an array of strings, where each string is an argument to
// `VBoxManage`. Each argument is treated as a [configuration
// template](/docs/templates/engine). The only available
// variable is `Name` which is replaced with the unique name of the VM, which is
// required for many VBoxManage calls.
VBoxManage [][]string `mapstructure:"vboxmanage" required:"false"`
2019-06-19 11:07:23 -04:00
// Identical to vboxmanage,
// except that it is run after the virtual machine is shutdown, and before the
// virtual machine is exported.
VBoxManagePost [][]string `mapstructure:"vboxmanage_post" required:"false"`
2013-12-22 12:24:29 -05:00
}
func (c *VBoxManageConfig) Prepare(ctx *interpolate.Context) []error {
2013-12-22 12:24:29 -05:00
if c.VBoxManage == nil {
c.VBoxManage = make([][]string, 0)
}
2019-06-19 11:07:23 -04:00
if c.VBoxManagePost == nil {
c.VBoxManagePost = make([][]string, 0)
}
return nil
2013-12-22 12:24:29 -05:00
}