Skip to content

Commit 330dc55

Browse files
authored
chore: update virtual hardware versions (#211)
- Updates `version` to an `int` instead of a string. - Adds a check in `Prepare()` to ensure the value is > the minimum. - Adds constants for the minimum and default virtual hardware versions. NOTE: - Minimum is now 13 instead of 9. - Default is 19 instead of 9. Signed-off-by: Ryan Johnson <[email protected]> - Updates the documentation in `config.go`.
1 parent 88a052e commit 330dc55

File tree

6 files changed

+124
-126
lines changed

6 files changed

+124
-126
lines changed

.web-docs/components/builder/iso/README.md

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -78,47 +78,44 @@ necessary for this build to succeed and can be found further down the page.
7878

7979
<!-- Code generated from the comments of the Config struct in builder/vmware/iso/config.go; DO NOT EDIT MANUALLY -->
8080

81-
- `disk_size` (uint) - The size of the hard disk for the VM in megabytes.
82-
The builder uses expandable, not fixed-size virtual hard disks, so the
83-
actual file representing the disk will not use the full size unless it
84-
is full. By default this is set to 40000 (about 40 GB).
85-
86-
- `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used
87-
by the cdrom device. This is chosen by default based on the disk adapter
88-
type. VMware tends to lean towards ide for the cdrom device unless
89-
sata is chosen for the disk adapter and so Packer attempts to mirror
90-
this logic. This field can be specified as either ide, sata, or scsi.
91-
92-
- `guest_os_type` (string) - The guest OS type being installed. This will be
93-
set in the VMware VMX. By default this is other. By specifying a more
94-
specific OS type, VMware may perform some optimizations or virtual hardware
95-
changes to better support the operating system running in the
96-
virtual machine. Valid values differ by platform and version numbers, and may
97-
not match other VMware API's representation of the guest OS names. Consult your
98-
platform for valid values.
99-
100-
- `version` (string) - The [vmx hardware
101-
version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
102-
for the new virtual machine. Only the default value has been tested, any
103-
other value is experimental. Default value is `9`.
104-
105-
- `vm_name` (string) - This is the name of the VMX file for the new virtual
106-
machine, without the file extension. By default this is packer-BUILDNAME,
107-
where "BUILDNAME" is the name of the build.
108-
109-
- `vmx_disk_template_path` (string) - VMX Disk Template Path
110-
111-
- `vmx_template_path` (string) - Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
112-
defines the contents of the virtual machine VMX file for VMware. The
113-
engine has access to the template variables `{{ .DiskNumber }}` and
114-
`{{ .DiskName }}`.
81+
- `disk_size` (uint) - The size of the disk in megabytes. The builder uses expandable virtual
82+
hard disks. The file that backs the virtual disk will only grow as needed
83+
up to this size. Default is 40000 (~40 GB).
84+
85+
- `cdrom_adapter_type` (string) - The type of controller to use for the CD-ROM device.
86+
Allowed values are `ide`, `sata`, and `scsi`.
87+
88+
- `guest_os_type` (string) - The guest operating system identifier for the virtual machine.
89+
Defaults to `other`.
90+
91+
- `version` (int) - The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
92+
for more information on supported virtual hardware versions.
93+
Minimum is 13. Default is 19.
94+
95+
- `vm_name` (string) - The name of the virtual machine. This represents the name of the virtual
96+
machine `.vmx` configuration file without the file extension.
97+
Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
98+
build.
99+
100+
- `vmx_disk_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
101+
for defining the contents of a virtual machine `.vmx` configuration file
102+
for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
103+
`{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
104+
the template.
105+
106+
~> **Note:** This option is intended for advanced users, as incorrect
107+
configurations can lead to non-functional virtual machines.
108+
109+
- `vmx_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
110+
for defining the contents of a virtual machine `.vmx` configuration file.
115111

116-
This is for **advanced users only** as this can render the virtual machine
117-
non-functional. See below for more information. For basic VMX
118-
modifications, try `vmx_data` first.
112+
~> **Note:** This option is intended for advanced users, as incorrect
113+
configurations can lead to non-functional virtual machines. For simpler
114+
modifications of the virtual machine`.vmx` configuration file, consider
115+
using `vmx_data` option.
119116

120-
- `snapshot_name` (string) - This is the name of the initial snapshot created after provisioning and cleanup.
121-
if left blank, no initial snapshot will be created
117+
- `snapshot_name` (string) - The name of the virtual machine snapshot to be created.
118+
If this field is left empty, no snapshot will be created.
122119

123120
- `vhv_enabled` (bool) - Enable virtual hardware-assisted virtualization for the virtual machine.
124121
Defaults to `false`.

builder/vmware/iso/builder_test.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515

1616
func testConfig() map[string]interface{} {
1717
return map[string]interface{}{
18+
"version": 21,
1819
"iso_checksum": "md5:0B0F137F17AC10944716020B018F8126",
1920
"iso_url": "http://www.packer.io",
2021
"shutdown_command": "foo",
@@ -47,8 +48,8 @@ func TestBuilderPrepare_Defaults(t *testing.T) {
4748
t.Errorf("bad output dir: %s", b.config.OutputDir)
4849
}
4950

50-
if b.config.Version != "9" {
51-
t.Errorf("bad Version: %s", b.config.Version)
51+
if b.config.Version < minimumHardwareVersion {
52+
t.Errorf("bad version: %d, minimum hardware version: %d", b.config.Version, minimumHardwareVersion)
5253
}
5354

5455
if b.config.VMName != "packer-foo" {
@@ -308,7 +309,7 @@ func TestBuilderPrepare_Export(t *testing.T) {
308309
outCfg.Format, tc.Reason)
309310
}
310311
if outCfg.SkipExport != tc.ExpectedSkipExportValue {
311-
t.Fatalf("For SkipExport expected %t but recieved %t",
312+
t.Fatalf("For SkipExport expected %t but received %t",
312313
tc.ExpectedSkipExportValue, outCfg.SkipExport)
313314
}
314315
}

builder/vmware/iso/config.go

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,18 @@ import (
1515
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
1616
"github.com/hashicorp/packer-plugin-sdk/common"
1717
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
18+
"github.com/hashicorp/packer-plugin-sdk/packer"
1819
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
1920
"github.com/hashicorp/packer-plugin-sdk/shutdowncommand"
2021
"github.com/hashicorp/packer-plugin-sdk/template/config"
2122
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
2223
vmwcommon "github.com/hashicorp/packer-plugin-vmware/builder/vmware/common"
2324
)
2425

26+
// Reference: https://knowledge.broadcom.com/external/article?articleNumber=315655
27+
const minimumHardwareVersion = 13
28+
const defaultHardwareVersion = 19
29+
2530
type Config struct {
2631
common.PackerConfig `mapstructure:",squash"`
2732
commonsteps.HTTPConfig `mapstructure:",squash"`
@@ -39,47 +44,44 @@ type Config struct {
3944
vmwcommon.VMXConfig `mapstructure:",squash"`
4045
vmwcommon.ExportConfig `mapstructure:",squash"`
4146
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).
4650
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`.
5253
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`.
6056
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.
6965
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.
7174
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.
7677
//
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.
8082
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.
8385
SnapshotName string `mapstructure:"snapshot_name" required:"false"`
8486
// Enable virtual hardware-assisted virtualization for the virtual machine.
8587
// Defaults to `false`.
@@ -156,8 +158,10 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
156158
c.VMName = fmt.Sprintf("packer-%s", c.PackerBuildName)
157159
}
158160

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))
161165
}
162166

163167
if c.VMXTemplatePath != "" {

builder/vmware/iso/config.hcl2spec.go

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

builder/vmware/iso/step_create_vmx.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
147147

148148
rawBytes, err := io.ReadAll(f)
149149
if err != nil {
150-
err := fmt.Errorf("rrror reading VMX disk template: %s", err)
150+
err := fmt.Errorf("error reading VMX disk template: %s", err)
151151
state.Put("error", err)
152152
ui.Error(err.Error())
153153
return multistep.ActionHalt
@@ -169,12 +169,11 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi
169169
}
170170

171171
templateData := vmxTemplateData{
172-
Name: config.VMName,
173-
GuestOS: config.GuestOSType,
174-
DiskName: config.DiskName,
175-
Version: config.Version,
176-
ISOPath: isoPath,
177-
172+
Name: config.VMName,
173+
GuestOS: config.GuestOSType,
174+
DiskName: config.DiskName,
175+
Version: strconv.Itoa(config.Version),
176+
ISOPath: isoPath,
178177
Network_Adapter: "e1000",
179178

180179
Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[config.HWConfig.Sound],

docs-partials/builder/vmware/iso/Config-not-required.mdx

Lines changed: 36 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,43 @@
11
<!-- Code generated from the comments of the Config struct in builder/vmware/iso/config.go; DO NOT EDIT MANUALLY -->
22

3-
- `disk_size` (uint) - The size of the hard disk for the VM in megabytes.
4-
The builder uses expandable, not fixed-size virtual hard disks, so the
5-
actual file representing the disk will not use the full size unless it
6-
is full. By default this is set to 40000 (about 40 GB).
7-
8-
- `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used
9-
by the cdrom device. This is chosen by default based on the disk adapter
10-
type. VMware tends to lean towards ide for the cdrom device unless
11-
sata is chosen for the disk adapter and so Packer attempts to mirror
12-
this logic. This field can be specified as either ide, sata, or scsi.
13-
14-
- `guest_os_type` (string) - The guest OS type being installed. This will be
15-
set in the VMware VMX. By default this is other. By specifying a more
16-
specific OS type, VMware may perform some optimizations or virtual hardware
17-
changes to better support the operating system running in the
18-
virtual machine. Valid values differ by platform and version numbers, and may
19-
not match other VMware API's representation of the guest OS names. Consult your
20-
platform for valid values.
21-
22-
- `version` (string) - The [vmx hardware
23-
version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
24-
for the new virtual machine. Only the default value has been tested, any
25-
other value is experimental. Default value is `9`.
26-
27-
- `vm_name` (string) - This is the name of the VMX file for the new virtual
28-
machine, without the file extension. By default this is packer-BUILDNAME,
29-
where "BUILDNAME" is the name of the build.
30-
31-
- `vmx_disk_template_path` (string) - VMX Disk Template Path
32-
33-
- `vmx_template_path` (string) - Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
34-
defines the contents of the virtual machine VMX file for VMware. The
35-
engine has access to the template variables `{{ .DiskNumber }}` and
36-
`{{ .DiskName }}`.
3+
- `disk_size` (uint) - The size of the disk in megabytes. The builder uses expandable virtual
4+
hard disks. The file that backs the virtual disk will only grow as needed
5+
up to this size. Default is 40000 (~40 GB).
6+
7+
- `cdrom_adapter_type` (string) - The type of controller to use for the CD-ROM device.
8+
Allowed values are `ide`, `sata`, and `scsi`.
9+
10+
- `guest_os_type` (string) - The guest operating system identifier for the virtual machine.
11+
Defaults to `other`.
12+
13+
- `version` (int) - The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
14+
for more information on supported virtual hardware versions.
15+
Minimum is 13. Default is 19.
16+
17+
- `vm_name` (string) - The name of the virtual machine. This represents the name of the virtual
18+
machine `.vmx` configuration file without the file extension.
19+
Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
20+
build.
21+
22+
- `vmx_disk_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
23+
for defining the contents of a virtual machine `.vmx` configuration file
24+
for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
25+
`{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
26+
the template.
3727

38-
This is for **advanced users only** as this can render the virtual machine
39-
non-functional. See below for more information. For basic VMX
40-
modifications, try `vmx_data` first.
28+
~> **Note:** This option is intended for advanced users, as incorrect
29+
configurations can lead to non-functional virtual machines.
4130

42-
- `snapshot_name` (string) - This is the name of the initial snapshot created after provisioning and cleanup.
43-
if left blank, no initial snapshot will be created
31+
- `vmx_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
32+
for defining the contents of a virtual machine `.vmx` configuration file.
33+
34+
~> **Note:** This option is intended for advanced users, as incorrect
35+
configurations can lead to non-functional virtual machines. For simpler
36+
modifications of the virtual machine`.vmx` configuration file, consider
37+
using `vmx_data` option.
38+
39+
- `snapshot_name` (string) - The name of the virtual machine snapshot to be created.
40+
If this field is left empty, no snapshot will be created.
4441

4542
- `vhv_enabled` (bool) - Enable virtual hardware-assisted virtualization for the virtual machine.
4643
Defaults to `false`.

0 commit comments

Comments
 (0)