From 99800619b7c00df91bc358483a373071c6609104 Mon Sep 17 00:00:00 2001 From: Sylvia Moss Date: Thu, 20 Aug 2020 15:43:38 +0200 Subject: [PATCH] Add HCL2 examples to the virtualbox builders (#9788) --- builder/virtualbox/common/export_config.go | 14 ++++ .../virtualbox/common/vboxmanage_config.go | 41 ++++++++--- builder/virtualbox/iso/builder.go | 8 ++ .../pages/docs/builders/virtualbox/iso.mdx | 73 ++++++++++--------- .../pages/docs/builders/virtualbox/ovf.mdx | 46 +++++------- website/pages/docs/builders/virtualbox/vm.mdx | 43 +++++------ .../common/ExportConfig-not-required.mdx | 14 ++++ .../common/VBoxManageConfig-not-required.mdx | 36 ++++++--- .../virtualbox/common/VBoxManageConfig.mdx | 7 ++ .../virtualbox/iso/Config-not-required.mdx | 8 ++ .../builders/virtualbox-ssh-key-pair.mdx | 17 +++-- 11 files changed, 199 insertions(+), 108 deletions(-) create mode 100644 website/pages/partials/builder/virtualbox/common/VBoxManageConfig.mdx diff --git a/builder/virtualbox/common/export_config.go b/builder/virtualbox/common/export_config.go index a6a09294a..f8a468265 100644 --- a/builder/virtualbox/common/export_config.go +++ b/builder/virtualbox/common/export_config.go @@ -17,6 +17,7 @@ type ExportConfig struct { // This can be useful for passing product information to include in the // resulting appliance file. Packer JSON configuration file example: // + // In JSON: // ```json // { // "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 // description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf) // may contain arbitrary strings; the GUI interprets HTML formatting. However, diff --git a/builder/virtualbox/common/vboxmanage_config.go b/builder/virtualbox/common/vboxmanage_config.go index b24b42654..c73010c2a 100644 --- a/builder/virtualbox/common/vboxmanage_config.go +++ b/builder/virtualbox/common/vboxmanage_config.go @@ -6,17 +6,40 @@ import ( "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 { // Custom `VBoxManage` commands to execute in order to further customize - // the virtual machine being created. The value of this is an array of - // commands to execute. The commands are executed in the order defined in - // the template. For each command, the command is defined itself as an - // array of strings, where each string represents a single argument on the - // command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each - // arg is treated as a [configuration - // template](/docs/templates/engine), where the `Name` variable is - // replaced with the VM name. More details on how to use `VBoxManage` are - // below. + // 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"` // Identical to vboxmanage, // except that it is run after the virtual machine is shutdown, and before the diff --git a/builder/virtualbox/iso/builder.go b/builder/virtualbox/iso/builder.go index 9011680c1..cc7c74e14 100644 --- a/builder/virtualbox/iso/builder.go +++ b/builder/virtualbox/iso/builder.go @@ -89,12 +89,20 @@ type Config struct { // pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack) // and you will need to enable EFI mode for nvme to work, ex: // + // In JSON: // ```json // "vboxmanage": [ // [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ], // ] // ``` // + // In HCL2: + // ```hcl + // vboxmanage = [ + // [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ], + // ] + // ``` + // HardDriveInterface string `mapstructure:"hard_drive_interface" required:"false"` // 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 diff --git a/website/pages/docs/builders/virtualbox/iso.mdx b/website/pages/docs/builders/virtualbox/iso.mdx index b22dc0444..086732ac6 100644 --- a/website/pages/docs/builders/virtualbox/iso.mdx +++ b/website/pages/docs/builders/virtualbox/iso.mdx @@ -47,7 +47,6 @@ self-install. Still, the example serves to show the basic configuration: ```hcl - source "virtualbox-iso" "basic-example" { guest_os_type = "Ubuntu_64" 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 +@include 'builder/virtualbox/common/VBoxManageConfig.mdx' + #### Optional: @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 "boot_keygroup_interval" in your Packer template, for example: + + + + ```json { "builders": [ { - "type": "virtualbox", + "type": "virtualbox-iso", "boot_keygroup_interval": "500ms" ... } @@ -209,6 +214,19 @@ contention. If you notice missing keys, you can tune this delay by specifying } ``` + + + +```hcl +source "virtualbox-iso" "basic-example" { + boot_keygroup_interval = "500ms" + # ... +} +``` + + + + #### Optional: @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 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 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: + + + ```json - "iso_interface": "sata", - "vboxmanage": [ - [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ] - ] +"iso_interface": "sata", +"vboxmanage": [ + [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ] +] ``` + + + + +```hcl +iso_interface = "sata" +vboxmanage = [ + [ "modifyvm", "{{.Name}}", "--firmware", "EFI" ] +] +``` + + + diff --git a/website/pages/docs/builders/virtualbox/ovf.mdx b/website/pages/docs/builders/virtualbox/ovf.mdx index 6f253faf4..876fdd43a 100644 --- a/website/pages/docs/builders/virtualbox/ovf.mdx +++ b/website/pages/docs/builders/virtualbox/ovf.mdx @@ -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 "boot_keygroup_interval" in your Packer template, for example: + + + ```json { "builders": [ { - "type": "virtualbox", + "type": "virtualbox-ovf", "boot_keygroup_interval": "500ms" ... } @@ -198,6 +201,19 @@ contention. If you notice missing keys, you can tune this delay by specifying } ``` + + + +```hcl +source "virtualbox-ovf" "basic-example" { + boot_keygroup_interval = "500ms" + # ... +} +``` + + + + #### Optional: @include 'common/bootcommand/BootConfig-not-required.mdx' @@ -221,31 +237,7 @@ 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. +@include 'builder/virtualbox/common/VBoxManageConfig.mdx' -Extra VBoxManage commands are defined in the template in the `vboxmanage` -section. An example is shown below that sets the memory and number of CPUs -within the virtual machine: +@include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx' -```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. diff --git a/website/pages/docs/builders/virtualbox/vm.mdx b/website/pages/docs/builders/virtualbox/vm.mdx index 0736bc849..200b4aede 100644 --- a/website/pages/docs/builders/virtualbox/vm.mdx +++ b/website/pages/docs/builders/virtualbox/vm.mdx @@ -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 "boot_keygroup_interval" in your Packer template, for example: + + + ```json { "builders": [ { - "type": "virtualbox", + "type": "virtualbox-vm", "boot_keygroup_interval": "500ms" ... } @@ -212,6 +215,19 @@ contention. If you notice missing keys, you can tune this delay by specifying } ``` + + + +```hcl +source "virtualbox-vm" "basic-example" { + boot_keygroup_interval = "500ms" + # ... +} +``` + + + + #### Optional: @include 'common/bootcommand/BootConfig-not-required.mdx' @@ -235,27 +251,6 @@ 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. +@include 'builder/virtualbox/common/VBoxManageConfig.mdx' -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. +@include 'builder/virtualbox/common/VBoxManageConfig-not-required.mdx' diff --git a/website/pages/partials/builder/virtualbox/common/ExportConfig-not-required.mdx b/website/pages/partials/builder/virtualbox/common/ExportConfig-not-required.mdx index 99908fa62..11337947e 100644 --- a/website/pages/partials/builder/virtualbox/common/ExportConfig-not-required.mdx +++ b/website/pages/partials/builder/virtualbox/common/ExportConfig-not-required.mdx @@ -8,6 +8,7 @@ This can be useful for passing product information to include in the resulting appliance file. Packer JSON configuration file example: + In JSON: ```json { "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 description](https://www.virtualbox.org/manual/ch09.html#vboxmanage-export-ovf) may contain arbitrary strings; the GUI interprets HTML formatting. However, diff --git a/website/pages/partials/builder/virtualbox/common/VBoxManageConfig-not-required.mdx b/website/pages/partials/builder/virtualbox/common/VBoxManageConfig-not-required.mdx index a5b3f982e..6ebea3a8d 100644 --- a/website/pages/partials/builder/virtualbox/common/VBoxManageConfig-not-required.mdx +++ b/website/pages/partials/builder/virtualbox/common/VBoxManageConfig-not-required.mdx @@ -1,15 +1,33 @@ - `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 - commands to execute. The commands are executed in the order defined in - the template. For each command, the command is defined itself as an - array of strings, where each string represents a single argument on the - command-line to `VBoxManage` (but excluding `VBoxManage` itself). Each - arg is treated as a [configuration - template](/docs/templates/engine), where the `Name` variable is - replaced with the VM name. More details on how to use `VBoxManage` are - below. + 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_post` ([][]string) - Identical to vboxmanage, except that it is run after the virtual machine is shutdown, and before the diff --git a/website/pages/partials/builder/virtualbox/common/VBoxManageConfig.mdx b/website/pages/partials/builder/virtualbox/common/VBoxManageConfig.mdx new file mode 100644 index 000000000..9a03bfc59 --- /dev/null +++ b/website/pages/partials/builder/virtualbox/common/VBoxManageConfig.mdx @@ -0,0 +1,7 @@ + + +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. diff --git a/website/pages/partials/builder/virtualbox/iso/Config-not-required.mdx b/website/pages/partials/builder/virtualbox/iso/Config-not-required.mdx index e006546fd..89b15859b 100644 --- a/website/pages/partials/builder/virtualbox/iso/Config-not-required.mdx +++ b/website/pages/partials/builder/virtualbox/iso/Config-not-required.mdx @@ -46,11 +46,19 @@ pack](https://www.virtualbox.org/wiki/Downloads#VirtualBox6.0.14OracleVMVirtualBoxExtensionPack) and you will need to enable EFI mode for nvme to work, ex: + In JSON: ```json "vboxmanage": [ [ "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 to 1. VirtualBox supports up to 30 ports on a maximum of 1 SATA diff --git a/website/pages/partials/builders/virtualbox-ssh-key-pair.mdx b/website/pages/partials/builders/virtualbox-ssh-key-pair.mdx index 306aa2c10..a61ef5e2d 100644 --- a/website/pages/partials/builders/virtualbox-ssh-key-pair.mdx +++ b/website/pages/partials/builders/virtualbox-ssh-key-pair.mdx @@ -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 encoded string by appending `| urlquery` to the variable: +In JSON: ```json -{ - "type": "virtualbox-iso", - "boot_command": [ - " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}" - ] -} +"boot_command": [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}" +] +``` + +In HCL2: +```hcl +boot_command = [ + " text ks=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ks.cfg PACKER_USER={{ user `username` }} PACKER_AUTHORIZED_KEY={{ .SSHPublicKey | urlquery }}" +] ``` A kickstart could then leverage those fields from the kernel command line by