@@ -15,13 +15,18 @@ import (
15
15
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
16
16
"github.com/hashicorp/packer-plugin-sdk/common"
17
17
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
18
+ "github.com/hashicorp/packer-plugin-sdk/packer"
18
19
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
19
20
"github.com/hashicorp/packer-plugin-sdk/shutdowncommand"
20
21
"github.com/hashicorp/packer-plugin-sdk/template/config"
21
22
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
22
23
vmwcommon "github.com/hashicorp/packer-plugin-vmware/builder/vmware/common"
23
24
)
24
25
26
+ // Reference: https://knowledge.broadcom.com/external/article?articleNumber=315655
27
+ const minimumHardwareVersion = 13
28
+ const defaultHardwareVersion = 19
29
+
25
30
type Config struct {
26
31
common.PackerConfig `mapstructure:",squash"`
27
32
commonsteps.HTTPConfig `mapstructure:",squash"`
@@ -39,47 +44,44 @@ type Config struct {
39
44
vmwcommon.VMXConfig `mapstructure:",squash"`
40
45
vmwcommon.ExportConfig `mapstructure:",squash"`
41
46
vmwcommon.DiskConfig `mapstructure:",squash"`
42
- // The size of the hard disk for the VM in megabytes.
43
- // The builder uses expandable, not fixed-size virtual hard disks, so the
44
- // actual file representing the disk will not use the full size unless it
45
- // is full. By default this is set to 40000 (about 40 GB).
47
+ // The size of the disk in megabytes. The builder uses expandable virtual
48
+ // hard disks. The file that backs the virtual disk will only grow as needed
49
+ // up to this size. Default is 40000 (~40 GB).
46
50
DiskSize uint `mapstructure:"disk_size" required:"false"`
47
- // The adapter type (or bus) that will be used
48
- // by the cdrom device. This is chosen by default based on the disk adapter
49
- // type. VMware tends to lean towards ide for the cdrom device unless
50
- // sata is chosen for the disk adapter and so Packer attempts to mirror
51
- // this logic. This field can be specified as either ide, sata, or scsi.
51
+ // The type of controller to use for the CD-ROM device.
52
+ // Allowed values are `ide`, `sata`, and `scsi`.
52
53
CdromAdapterType string `mapstructure:"cdrom_adapter_type" required:"false"`
53
- // The guest OS type being installed. This will be
54
- // set in the VMware VMX. By default this is other. By specifying a more
55
- // specific OS type, VMware may perform some optimizations or virtual hardware
56
- // changes to better support the operating system running in the
57
- // virtual machine. Valid values differ by platform and version numbers, and may
58
- // not match other VMware API's representation of the guest OS names. Consult your
59
- // platform for valid values.
54
+ // The guest operating system identifier for the virtual machine.
55
+ // Defaults to `other`.
60
56
GuestOSType string `mapstructure:"guest_os_type" required:"false"`
61
- // The [vmx hardware
62
- // version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
63
- // for the new virtual machine. Only the default value has been tested, any
64
- // other value is experimental. Default value is `9`.
65
- Version string `mapstructure:"version" required:"false"`
66
- // This is the name of the VMX file for the new virtual
67
- // machine, without the file extension. By default this is packer-BUILDNAME,
68
- // where "BUILDNAME" is the name of the build.
57
+ // The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
58
+ // for more information on supported virtual hardware versions.
59
+ // Minimum is 13. Default is 19.
60
+ Version int `mapstructure:"version" required:"false"`
61
+ // The name of the virtual machine. This represents the name of the virtual
62
+ // machine `.vmx` configuration file without the file extension.
63
+ // Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
64
+ // build.
69
65
VMName string `mapstructure:"vm_name" required:"false"`
70
-
66
+ // The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
67
+ // for defining the contents of a virtual machine `.vmx` configuration file
68
+ // for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
69
+ // `{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
70
+ // the template.
71
+ //
72
+ // ~> **Note:** This option is intended for advanced users, as incorrect
73
+ // configurations can lead to non-functional virtual machines.
71
74
VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"`
72
- // Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
73
- // defines the contents of the virtual machine VMX file for VMware. The
74
- // engine has access to the template variables `{{ .DiskNumber }}` and
75
- // `{{ .DiskName }}`.
75
+ // The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
76
+ // for defining the contents of a virtual machine `.vmx` configuration file.
76
77
//
77
- // This is for **advanced users only** as this can render the virtual machine
78
- // non-functional. See below for more information. For basic VMX
79
- // modifications, try `vmx_data` first.
78
+ // ~> **Note:** This option is intended for advanced users, as incorrect
79
+ // configurations can lead to non-functional virtual machines. For simpler
80
+ // modifications of the virtual machine`.vmx` configuration file, consider
81
+ // using `vmx_data` option.
80
82
VMXTemplatePath string `mapstructure:"vmx_template_path" required:"false"`
81
- // This is the name of the initial snapshot created after provisioning and cleanup .
82
- // if left blank , no initial snapshot will be created
83
+ // The name of the virtual machine snapshot to be created .
84
+ // If this field is left empty , no snapshot will be created.
83
85
SnapshotName string `mapstructure:"snapshot_name" required:"false"`
84
86
// Enable virtual hardware-assisted virtualization for the virtual machine.
85
87
// Defaults to `false`.
@@ -156,8 +158,10 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
156
158
c .VMName = fmt .Sprintf ("packer-%s" , c .PackerBuildName )
157
159
}
158
160
159
- if c .Version == "" {
160
- c .Version = "9"
161
+ if c .Version == 0 {
162
+ c .Version = defaultHardwareVersion
163
+ } else if c .Version < minimumHardwareVersion {
164
+ errs = packer .MultiErrorAppend (errs , fmt .Errorf ("invalid 'version' %d, minimum hardware version: %d" , c .Version , minimumHardwareVersion ))
161
165
}
162
166
163
167
if c .VMXTemplatePath != "" {
0 commit comments