Skip to content

Commit

Permalink
fixup! Add boot steps configuration option
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-carlborg committed Nov 7, 2022
1 parent e00cc19 commit 4de68fb
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 2 deletions.
44 changes: 44 additions & 0 deletions builder/qemu/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,45 @@ type Config struct {
// * ARM: tpm-tis-device
// * PPC (p-series): tpm-spapr
TPMType string `mapstructure:"tpm_device_type" required:"false"`
// This is an array of tuples of boot commands, to type when the virtual
// machine is booted. The first element of the tuple is the actual boot
// command. The second element of the tuple, which is optional, is a
// description of what the boot command does. This is intended to be used for
// interactive installers that requires many commands to complete the
// installation. Both the command and the description will be printed when
// logging is enabled. When debug mode is enabled Packer will pause after
// typing each boot command. This will make it easier to follow along the
// installation process and make sure the Packer and the installer are in
// sync. `boot_steps` and `boot_commands` are mutually exclusive.
//
// Example:
//
// In HCL:
// ```hcl
// boot_steps = [
// ["1<enter><wait5>", "Install NetBSD"],
// ["a<enter><wait5>", "Installation messages in English"],
// ["a<enter><wait5>", "Keyboard type: unchanged"],
//
// ["a<enter><wait5>", "Install NetBSD to hard disk"],
// ["b<enter><wait5>", "Yes"]
// ]
// ```
//
// In JSON:
// ```json
// {
// "boot_steps": [
// ["1<enter><wait5>", "Install NetBSD"],
// ["a<enter><wait5>", "Installation messages in English"],
// ["a<enter><wait5>", "Keyboard type: unchanged"],
//
// ["a<enter><wait5>", "Install NetBSD to hard disk"],
// ["b<enter><wait5>", "Yes"]
// ]
// }
// ```
BootSteps [][]string `mapstructure:"boot_steps" required:"false"`

// TODO(mitchellh): deprecate
RunOnce bool `mapstructure:"run_once"`
Expand Down Expand Up @@ -759,6 +798,11 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
errs, fmt.Errorf("net_bridge is only supported in Linux based OSes"))
}

if len(c.BootCommand) > 0 && len(c.BootSteps) > 0 {
errs = packersdk.MultiErrorAppend(errs,
fmt.Errorf("Both boot_command and boot_steps cannot be used"))
}

if c.NetBridge != "" || c.VNCUsePassword {
c.QMPEnable = true
}
Expand Down
4 changes: 2 additions & 2 deletions builder/qemu/config.hcl2spec.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

39 changes: 39 additions & 0 deletions docs-partials/builder/qemu/Config-not-required.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -350,4 +350,43 @@
* ARM: tpm-tis-device
* PPC (p-series): tpm-spapr
- `boot_steps` ([][]string) - This is an array of tuples of boot commands, to type when the virtual
machine is booted. The first element of the tuple is the actual boot
command. The second element of the tuple, which is optional, is a
description of what the boot command does. This is intended to be used for
interactive installers that requires many commands to complete the
installation. Both the command and the description will be printed when
logging is enabled. When debug mode is enabled Packer will pause after
typing each boot command. This will make it easier to follow along the
installation process and make sure the Packer and the installer are in
sync. `boot_steps` and `boot_commands` are mutually exclusive.
Example:
In HCL:
```hcl
boot_steps = [
["1<enter><wait5>", "Install NetBSD"],
["a<enter><wait5>", "Installation messages in English"],
["a<enter><wait5>", "Keyboard type: unchanged"],

["a<enter><wait5>", "Install NetBSD to hard disk"],
["b<enter><wait5>", "Yes"]
]
```
In JSON:
```json
{
"boot_steps": [
["1<enter><wait5>", "Install NetBSD"],
["a<enter><wait5>", "Installation messages in English"],
["a<enter><wait5>", "Keyboard type: unchanged"],

["a<enter><wait5>", "Install NetBSD to hard disk"],
["b<enter><wait5>", "Yes"]
]
}
```
<!-- End of code generated from the comments of the Config struct in builder/qemu/config.go; -->

0 comments on commit 4de68fb

Please sign in to comment.