Add HCL2 examples to the virtualbox builders (#9788)

This commit is contained in:
Sylvia Moss 2020-08-20 15:43:38 +02:00 committed by GitHub
parent 5b27fc7d61
commit 99800619b7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 199 additions and 108 deletions

View File

@ -17,6 +17,7 @@ type ExportConfig struct {
// This can be useful for passing product information to include in the // This can be useful for passing product information to include in the
// resulting appliance file. Packer JSON configuration file example: // resulting appliance file. Packer JSON configuration file example:
// //
// In JSON:
// ```json // ```json
// { // {
// "type": "virtualbox-iso", // "type": "virtualbox-iso",
@ -31,6 +32,19 @@ type ExportConfig struct {
// } // }
// ``` // ```
// //
// In HCL2:
// ```hcl
// source "virtualbox-iso" "basic-example" {
// export_opts = [
// "--manifest",
// "--vsys", "0",
// "--description", "{{user `vm_description`}}",
// "--version", "{{user `vm_version`}}"
// ]
// format = "ova"
// }
// ```
//
// A VirtualBox [VM // A VirtualBox [VM
// description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf) // description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf)
// may contain arbitrary strings; the GUI interprets HTML formatting. However, // may contain arbitrary strings; the GUI interprets HTML formatting. However,

View File

@ -6,17 +6,40 @@ import (
"github.com/hashicorp/packer/template/interpolate" "github.com/hashicorp/packer/template/interpolate"
) )
//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.
type VBoxManageConfig struct { type VBoxManageConfig struct {
// Custom `VBoxManage` commands to execute in order to further customize // Custom `VBoxManage` commands to execute in order to further customize
// the virtual machine being created. The value of this is an array of // the virtual machine being created. The example shown below sets the memory and number of CPUs
// commands to execute. The commands are executed in the order defined in // within the virtual machine:
// the template. For each command, the command is defined itself as an //
// array of strings, where each string represents a single argument on the // In JSON:
// command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each // ```json
// arg is treated as a [configuration // "vboxmanage": [
// template](/docs/templates/engine), where the `Name` variable is // ["modifyvm", "{{.Name}}", "--memory", "1024"],
// replaced with the VM name. More details on how to use `VBoxManage` are // ["modifyvm", "{{.Name}}", "--cpus", "2"]
// below. // ]
// ```
//
// 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"` VBoxManage [][]string `mapstructure:"vboxmanage" required:"false"`
// Identical to vboxmanage, // Identical to vboxmanage,
// except that it is run after the virtual machine is shutdown, and before the // except that it is run after the virtual machine is shutdown, and before the

View File

@ -89,12 +89,20 @@ type Config struct {
// pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack) // pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack)
// and you will need to enable EFI mode for nvme to work, ex: // and you will need to enable EFI mode for nvme to work, ex:
// //
// In JSON:
// ```json // ```json
// "vboxmanage": [ // "vboxmanage": [
// [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ], // [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
// ] // ]
// ``` // ```
// //
// In HCL2:
// ```hcl
// vboxmanage = [
// [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
// ]
// ```
//
HardDriveInterface string `mapstructure:"hard_drive_interface" required:"false"` HardDriveInterface string `mapstructure:"hard_drive_interface" required:"false"`
// The number of ports available on any SATA controller created, defaults // The number of ports available on any SATA controller created, defaults
// to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA // to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA

View File

@ -47,7 +47,6 @@ self-install. Still, the example serves to show the basic configuration:
<Tab heading="HCL2"> <Tab heading="HCL2">
```hcl ```hcl
source "virtualbox-iso" "basic-example" { source "virtualbox-iso" "basic-example" {
guest_os_type = "Ubuntu_64" guest_os_type = "Ubuntu_64"
iso_url = "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso" iso_url = "http://releases.ubuntu.com/12.04/ubuntu-12.04.5-server-amd64.iso"
@ -154,6 +153,8 @@ necessary for this build to succeed and can be found further down the page.
### VBox Manage configuration ### VBox Manage configuration
@include 'builder/virtualbox/common/VBoxManageConfig.mdx'
#### Optional: #### Optional:
@include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx' @include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx'
@ -197,11 +198,15 @@ delay of 100ms between groups. The delay alleviates issues with latency and CPU
contention. If you notice missing keys, you can tune this delay by specifying contention. If you notice missing keys, you can tune this delay by specifying
"boot_keygroup_interval" in your Packer template, for example: "boot_keygroup_interval" in your Packer template, for example:
<Tabs>
<Tab heading="JSON">
```json ```json
{ {
"builders": [ "builders": [
{ {
"type": "virtualbox", "type": "virtualbox-iso",
"boot_keygroup_interval": "500ms" "boot_keygroup_interval": "500ms"
... ...
} }
@ -209,6 +214,19 @@ contention. If you notice missing keys, you can tune this delay by specifying
} }
``` ```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-iso" "basic-example" {
boot_keygroup_interval = "500ms"
# ...
}
```
</Tab>
</Tabs>
#### Optional: #### Optional:
@include 'common/bootcommand/BootConfig-not-required.mdx' @include 'common/bootcommand/BootConfig-not-required.mdx'
@ -230,41 +248,30 @@ uploaded is controllable by `guest_additions_path`, and defaults to
"VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home "VBoxGuestAdditions.iso". Without an absolute path, it is uploaded to the home
directory of the SSH user. directory of the SSH user.
## VBoxManage Commands
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.
Extra VBoxManage commands are defined in the template in the `vboxmanage`
section. An example is shown below that sets the VRAM within the virtual machine:
```json
{
"vboxmanage": [["modifyvm", "{{.Name}}", "--vram", "64"]]
}
```
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.
## Creating an EFI enabled VM ## Creating an EFI enabled VM
If you want to create an EFI enabled VM, make sure you set the `iso_interface` If you want to create an EFI enabled VM, make sure you set the `iso_interface`
to "sata". Otherwise your attached drive will not be bootable. Example: to "sata". Otherwise your attached drive will not be bootable. Example:
<Tabs>
<Tab heading="JSON">
```json ```json
"iso_interface": "sata", "iso_interface": "sata",
"vboxmanage": [ "vboxmanage": [
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ] [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ]
] ]
``` ```
</Tab>
<Tab heading="HCL2">
```hcl
iso_interface = "sata"
vboxmanage = [
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ]
]
```
</Tab>
</Tabs>

View File

@ -186,11 +186,14 @@ delay of 100ms between groups. The delay alleviates issues with latency and CPU
contention. If you notice missing keys, you can tune this delay by specifying contention. If you notice missing keys, you can tune this delay by specifying
"boot_keygroup_interval" in your Packer template, for example: "boot_keygroup_interval" in your Packer template, for example:
<Tabs>
<Tab heading="JSON">
```json ```json
{ {
"builders": [ "builders": [
{ {
"type": "virtualbox", "type": "virtualbox-ovf",
"boot_keygroup_interval": "500ms" "boot_keygroup_interval": "500ms"
... ...
} }
@ -198,6 +201,19 @@ contention. If you notice missing keys, you can tune this delay by specifying
} }
``` ```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-ovf" "basic-example" {
boot_keygroup_interval = "500ms"
# ...
}
```
</Tab>
</Tabs>
#### Optional: #### Optional:
@include 'common/bootcommand/BootConfig-not-required.mdx' @include 'common/bootcommand/BootConfig-not-required.mdx'
@ -221,31 +237,7 @@ directory of the SSH user.
## VBoxManage Commands ## VBoxManage Commands
In order to perform extra customization of the virtual machine, a template can @include 'builder/virtualbox/common/VBoxManageConfig.mdx'
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.
Extra VBoxManage commands are defined in the template in the `vboxmanage` @include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx'
section. An example is shown below that sets the memory and number of CPUs
within the virtual machine:
```json
{
"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.

View File

@ -200,11 +200,14 @@ delay of 100ms between groups. The delay alleviates issues with latency and CPU
contention. If you notice missing keys, you can tune this delay by specifying contention. If you notice missing keys, you can tune this delay by specifying
"boot_keygroup_interval" in your Packer template, for example: "boot_keygroup_interval" in your Packer template, for example:
<Tabs>
<Tab heading="JSON">
```json ```json
{ {
"builders": [ "builders": [
{ {
"type": "virtualbox", "type": "virtualbox-vm",
"boot_keygroup_interval": "500ms" "boot_keygroup_interval": "500ms"
... ...
} }
@ -212,6 +215,19 @@ contention. If you notice missing keys, you can tune this delay by specifying
} }
``` ```
</Tab>
<Tab heading="HCL2">
```hcl
source "virtualbox-vm" "basic-example" {
boot_keygroup_interval = "500ms"
# ...
}
```
</Tab>
</Tabs>
#### Optional: #### Optional:
@include 'common/bootcommand/BootConfig-not-required.mdx' @include 'common/bootcommand/BootConfig-not-required.mdx'
@ -235,27 +251,6 @@ directory of the SSH user.
## VBoxManage Commands ## VBoxManage Commands
In order to perform extra customization of the virtual machine, a template can @include 'builder/virtualbox/common/VBoxManageConfig.mdx'
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.
Extra VBoxManage commands are defined in the template in the `vboxmanage` @include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx'
section. An example is shown below that sets the VRAM within the virtual machine:
```json
{
"vboxmanage": [["modifyvm", "{{.Name}}", "--vram", "64"]]
}
```
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.

View File

@ -8,6 +8,7 @@
This can be useful for passing product information to include in the This can be useful for passing product information to include in the
resulting appliance file. Packer JSON configuration file example: resulting appliance file. Packer JSON configuration file example:
In JSON:
```json ```json
{ {
"type": "virtualbox-iso", "type": "virtualbox-iso",
@ -22,6 +23,19 @@
} }
``` ```
In HCL2:
```hcl
source "virtualbox-iso" "basic-example" {
export_opts = [
"--manifest",
"--vsys", "0",
"--description", "{{user `vm_description`}}",
"--version", "{{user `vm_version`}}"
]
format = "ova"
}
```
A VirtualBox [VM A VirtualBox [VM
description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf) description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf)
may contain arbitrary strings; the GUI interprets HTML formatting. However, may contain arbitrary strings; the GUI interprets HTML formatting. However,

View File

@ -1,15 +1,33 @@
<!-- Code generated from the comments of the VBoxManageConfig struct in builder/virtualbox/common/vboxmanage_config.go; DO NOT EDIT MANUALLY --> <!-- Code generated from the comments of the VBoxManageConfig struct in builder/virtualbox/common/vboxmanage_config.go; DO NOT EDIT MANUALLY -->
- `vboxmanage` ([][]string) - Custom `VBoxManage` commands to execute in order to further customize - `vboxmanage` ([][]string) - Custom `VBoxManage` commands to execute in order to further customize
the virtual machine being created. The value of this is an array of the virtual machine being created. The example shown below sets the memory and number of CPUs
commands to execute. The commands are executed in the order defined in within the virtual machine:
the template. For each command, the command is defined itself as an
array of strings, where each string represents a single argument on the In JSON:
command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each ```json
arg is treated as a [configuration "vboxmanage": [
template](/docs/templates/engine), where the `Name` variable is ["modifyvm", "{{.Name}}", "--memory", "1024"],
replaced with the VM name. More details on how to use `VBoxManage` are ["modifyvm", "{{.Name}}", "--cpus", "2"]
below. ]
```
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_post` ([][]string) - Identical to vboxmanage, - `vboxmanage_post` ([][]string) - Identical to vboxmanage,
except that it is run after the virtual machine is shutdown, and before the except that it is run after the virtual machine is shutdown, and before the

View File

@ -0,0 +1,7 @@
<!-- Code generated from the comments of the VBoxManageConfig struct in builder/virtualbox/common/vboxmanage_config.go; DO NOT EDIT MANUALLY -->
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.

View File

@ -46,12 +46,20 @@
pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack) pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack)
and you will need to enable EFI mode for nvme to work, ex: and you will need to enable EFI mode for nvme to work, ex:
In JSON:
```json ```json
"vboxmanage": [ "vboxmanage": [
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ], [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
] ]
``` ```
In HCL2:
```hcl
vboxmanage = [
[ "modifyvm", "{{.Name}}", "--firmware", "EFI" ],
]
```
- `sata_port_count` (int) - The number of ports available on any SATA controller created, defaults - `sata_port_count` (int) - The number of ports available on any SATA controller created, defaults
to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA
controller. Increasing this value can be useful if you want to attach controller. Increasing this value can be useful if you want to attach

View File

@ -16,13 +16,18 @@ be accessed using the template variables.
For example, the public key can be provided in the boot command as a URL For example, the public key can be provided in the boot command as a URL
encoded string by appending `| urlquery` to the variable: encoded string by appending `| urlquery` to the variable:
In JSON:
```json ```json
{ "boot_command": [
"type": "virtualbox-iso", "<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}<enter>"
"boot_command": [ ]
"<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}<enter>" ```
]
} In HCL2:
```hcl
boot_command = [
"<up><wait><tab> text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}<enter>"
]
``` ```
A kickstart could then leverage those fields from the kernel command line by A kickstart could then leverage those fields from the kernel command line by