2019-05-31 08:27:41 -04:00
|
|
|
//go:generate struct-markdown
|
|
|
|
|
2013-12-26 17:26:09 -05:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2017-04-04 16:39:01 -04:00
|
|
|
"github.com/hashicorp/packer/template/interpolate"
|
2013-12-26 17:26:09 -05:00
|
|
|
)
|
|
|
|
|
2020-09-16 05:02:46 -04:00
|
|
|
// ~> **Note:** If [usb_keyboard](#usb_keyboard) or [vnc_over_websocket](#vnc_over_websocket) is set to true,
|
|
|
|
// any other VNC configuration will be ignored. If both are set to true, [usb_keyboard](#usb_keyboard) will be ignored
|
|
|
|
// and Packer will connect to the VM with VNC over websocket.
|
2013-12-26 17:26:09 -05:00
|
|
|
type RunConfig struct {
|
2019-05-28 11:50:58 -04:00
|
|
|
// Packer defaults to building VMware virtual machines
|
2019-06-06 10:29:25 -04:00
|
|
|
// by launching a GUI that shows the console of the machine being built. When
|
|
|
|
// this value is set to true, the machine will start without a console. For
|
|
|
|
// VMware machines, Packer will output VNC connection information in case you
|
|
|
|
// need to connect to the console to debug the build process.
|
2020-04-08 16:53:19 -04:00
|
|
|
// Some users have experienced issues where Packer cannot properly connect
|
|
|
|
// to a VM if it is headless; this appears to be a result of not ever having
|
|
|
|
// launched the VMWare GUI and accepting the evaluation license, or
|
|
|
|
// supplying a real license. If you experience this, launching VMWare and
|
|
|
|
// accepting the license should resolve your problem.
|
2019-05-28 11:50:58 -04:00
|
|
|
Headless bool `mapstructure:"headless" required:"false"`
|
|
|
|
// The IP address that should be
|
2019-06-06 10:29:25 -04:00
|
|
|
// binded to for VNC. By default packer will use 127.0.0.1 for this. If you
|
|
|
|
// wish to bind to all interfaces use 0.0.0.0.
|
|
|
|
VNCBindAddress string `mapstructure:"vnc_bind_address" required:"false"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// The minimum and maximum port
|
2019-06-06 10:29:25 -04:00
|
|
|
// to use for VNC access to the virtual machine. The builder uses VNC to type
|
|
|
|
// the initial boot_command. Because Packer generally runs in parallel,
|
|
|
|
// Packer uses a randomly chosen port in this range that appears available. By
|
|
|
|
// default this is 5900 to 6000. The minimum and maximum ports are
|
|
|
|
// inclusive.
|
|
|
|
VNCPortMin int `mapstructure:"vnc_port_min" required:"false"`
|
|
|
|
VNCPortMax int `mapstructure:"vnc_port_max"`
|
2019-05-28 11:50:58 -04:00
|
|
|
// Don't auto-generate a VNC password that
|
2019-06-06 10:29:25 -04:00
|
|
|
// is used to secure the VNC communication with the VM. This must be set to
|
|
|
|
// true if building on ESXi 6.5 and 6.7 with VNC enabled. Defaults to
|
|
|
|
// false.
|
|
|
|
VNCDisablePassword bool `mapstructure:"vnc_disable_password" required:"false"`
|
2020-09-16 05:02:46 -04:00
|
|
|
// When set to true, Packer will connect to the remote VNC server over a websocket connection
|
|
|
|
// and any other VNC configuration option will be ignored.
|
|
|
|
// Remote builds using ESXi 6.7+ allows to connect to the VNC server only over websocket,
|
|
|
|
// for these the `vnc_over_websocket` must be set to true.
|
|
|
|
// If [usb_keyboard](#usb_keyboard) is also set to true, `usb_keyboard` will be ignored and set to false.
|
|
|
|
VNCOverWebsocket bool `mapstructure:"vnc_over_websocket" required:"false"`
|
|
|
|
// Do not validate VNC over websocket server's TLS certificate. Defaults to `false`.
|
|
|
|
InsecureConnection bool `mapstructure:"insecure_connection" required:"false"`
|
2013-12-26 17:26:09 -05:00
|
|
|
}
|
|
|
|
|
2020-09-16 05:02:46 -04:00
|
|
|
func (c *RunConfig) Prepare(_ *interpolate.Context, bootConfig *BootConfigWrapper, driverConfig *DriverConfig) (warnings []string, errs []error) {
|
|
|
|
if c.VNCOverWebsocket {
|
|
|
|
if driverConfig.RemoteType == "" {
|
|
|
|
errs = append(errs, fmt.Errorf("'vnc_over_websocket' can only be used with remote VMWare builds."))
|
|
|
|
return
|
2020-09-11 10:46:33 -04:00
|
|
|
}
|
2020-09-16 05:02:46 -04:00
|
|
|
if bootConfig.USBKeyBoard {
|
|
|
|
warnings = append(warnings, "[WARN] Both 'usb_keyboard' and 'vnc_over_websocket' are set. "+
|
|
|
|
"The `usb_keyboard` option will be ignored and automatically set to false.")
|
|
|
|
bootConfig.USBKeyBoard = false
|
2020-09-11 10:46:33 -04:00
|
|
|
}
|
2020-09-16 05:02:46 -04:00
|
|
|
}
|
|
|
|
if bootConfig.USBKeyBoard || c.VNCOverWebsocket {
|
|
|
|
if c.VNCPortMin != 0 || c.VNCPortMax != 0 || c.VNCBindAddress != "" || c.VNCDisablePassword {
|
|
|
|
warnings = append(warnings, "[WARN] When one of 'usb_keyboard' and 'vnc_over_websocket' is set "+
|
|
|
|
"any other VNC configuration will be ignored.")
|
2020-09-11 10:46:33 -04:00
|
|
|
}
|
2020-09-16 05:02:46 -04:00
|
|
|
return
|
|
|
|
}
|
2016-05-23 09:02:56 -04:00
|
|
|
|
2020-09-16 05:02:46 -04:00
|
|
|
if c.VNCPortMin == 0 {
|
|
|
|
c.VNCPortMin = 5900
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VNCPortMax == 0 {
|
|
|
|
c.VNCPortMax = 6000
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.VNCBindAddress == "" {
|
|
|
|
c.VNCBindAddress = "127.0.0.1"
|
2014-09-05 15:10:40 -04:00
|
|
|
}
|
2020-09-16 05:02:46 -04:00
|
|
|
|
|
|
|
if c.VNCPortMin > c.VNCPortMax {
|
|
|
|
errs = append(errs, fmt.Errorf("vnc_port_min must be less than vnc_port_max"))
|
|
|
|
}
|
|
|
|
if c.VNCPortMin < 0 {
|
|
|
|
errs = append(errs, fmt.Errorf("vnc_port_min must be positive"))
|
|
|
|
}
|
|
|
|
|
2018-04-18 17:10:28 -04:00
|
|
|
return
|
2013-12-26 17:26:09 -05:00
|
|
|
}
|