Skip to content

Commit

Permalink
chore: update virtual hardware versions (#211)
Browse files Browse the repository at this point in the history
- 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 <ryan@tenthirtyam.org>
- Updates the documentation in `config.go`.
  • Loading branch information
tenthirtyam authored Jul 6, 2024
1 parent 88a052e commit 330dc55
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 126 deletions.
75 changes: 36 additions & 39 deletions .web-docs/components/builder/iso/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,47 +78,44 @@ necessary for this build to succeed and can be found further down the page.

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

- `disk_size` (uint) - The size of the hard disk for the VM in megabytes.
The builder uses expandable, not fixed-size virtual hard disks, so the
actual file representing the disk will not use the full size unless it
is full. By default this is set to 40000 (about 40 GB).

- `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used
by the cdrom device. This is chosen by default based on the disk adapter
type. VMware tends to lean towards ide for the cdrom device unless
sata is chosen for the disk adapter and so Packer attempts to mirror
this logic. This field can be specified as either ide, sata, or scsi.

- `guest_os_type` (string) - The guest OS type being installed. This will be
set in the VMware VMX. By default this is other. By specifying a more
specific OS type, VMware may perform some optimizations or virtual hardware
changes to better support the operating system running in the
virtual machine. Valid values differ by platform and version numbers, and may
not match other VMware API's representation of the guest OS names. Consult your
platform for valid values.

- `version` (string) - The [vmx hardware
version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
for the new virtual machine. Only the default value has been tested, any
other value is experimental. Default value is `9`.

- `vm_name` (string) - This is the name of the VMX file for the new virtual
machine, without the file extension. By default this is packer-BUILDNAME,
where "BUILDNAME" is the name of the build.

- `vmx_disk_template_path` (string) - VMX Disk Template Path

- `vmx_template_path` (string) - Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
defines the contents of the virtual machine VMX file for VMware. The
engine has access to the template variables `{{ .DiskNumber }}` and
`{{ .DiskName }}`.
- `disk_size` (uint) - The size of the disk in megabytes. The builder uses expandable virtual
hard disks. The file that backs the virtual disk will only grow as needed
up to this size. Default is 40000 (~40 GB).

- `cdrom_adapter_type` (string) - The type of controller to use for the CD-ROM device.
Allowed values are `ide`, `sata`, and `scsi`.

- `guest_os_type` (string) - The guest operating system identifier for the virtual machine.
Defaults to `other`.

- `version` (int) - The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
for more information on supported virtual hardware versions.
Minimum is 13. Default is 19.

- `vm_name` (string) - The name of the virtual machine. This represents the name of the virtual
machine `.vmx` configuration file without the file extension.
Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
build.

- `vmx_disk_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
for defining the contents of a virtual machine `.vmx` configuration file
for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
`{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
the template.

~> **Note:** This option is intended for advanced users, as incorrect
configurations can lead to non-functional virtual machines.

- `vmx_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
for defining the contents of a virtual machine `.vmx` configuration file.

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

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

- `vhv_enabled` (bool) - Enable virtual hardware-assisted virtualization for the virtual machine.
Defaults to `false`.
Expand Down
7 changes: 4 additions & 3 deletions builder/vmware/iso/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

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

if b.config.Version != "9" {
t.Errorf("bad Version: %s", b.config.Version)
if b.config.Version < minimumHardwareVersion {
t.Errorf("bad version: %d, minimum hardware version: %d", b.config.Version, minimumHardwareVersion)
}

if b.config.VMName != "packer-foo" {
Expand Down Expand Up @@ -308,7 +309,7 @@ func TestBuilderPrepare_Export(t *testing.T) {
outCfg.Format, tc.Reason)
}
if outCfg.SkipExport != tc.ExpectedSkipExportValue {
t.Fatalf("For SkipExport expected %t but recieved %t",
t.Fatalf("For SkipExport expected %t but received %t",
tc.ExpectedSkipExportValue, outCfg.SkipExport)
}
}
Expand Down
76 changes: 40 additions & 36 deletions builder/vmware/iso/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,18 @@ import (
"github.com/hashicorp/packer-plugin-sdk/bootcommand"
"github.com/hashicorp/packer-plugin-sdk/common"
"github.com/hashicorp/packer-plugin-sdk/multistep/commonsteps"
"github.com/hashicorp/packer-plugin-sdk/packer"
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
"github.com/hashicorp/packer-plugin-sdk/shutdowncommand"
"github.com/hashicorp/packer-plugin-sdk/template/config"
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
vmwcommon "github.com/hashicorp/packer-plugin-vmware/builder/vmware/common"
)

// Reference: https://knowledge.broadcom.com/external/article?articleNumber=315655
const minimumHardwareVersion = 13
const defaultHardwareVersion = 19

type Config struct {
common.PackerConfig `mapstructure:",squash"`
commonsteps.HTTPConfig `mapstructure:",squash"`
Expand All @@ -39,47 +44,44 @@ type Config struct {
vmwcommon.VMXConfig `mapstructure:",squash"`
vmwcommon.ExportConfig `mapstructure:",squash"`
vmwcommon.DiskConfig `mapstructure:",squash"`
// The size of the hard disk for the VM in megabytes.
// The builder uses expandable, not fixed-size virtual hard disks, so the
// actual file representing the disk will not use the full size unless it
// is full. By default this is set to 40000 (about 40 GB).
// The size of the disk in megabytes. The builder uses expandable virtual
// hard disks. The file that backs the virtual disk will only grow as needed
// up to this size. Default is 40000 (~40 GB).
DiskSize uint `mapstructure:"disk_size" required:"false"`
// The adapter type (or bus) that will be used
// by the cdrom device. This is chosen by default based on the disk adapter
// type. VMware tends to lean towards ide for the cdrom device unless
// sata is chosen for the disk adapter and so Packer attempts to mirror
// this logic. This field can be specified as either ide, sata, or scsi.
// The type of controller to use for the CD-ROM device.
// Allowed values are `ide`, `sata`, and `scsi`.
CdromAdapterType string `mapstructure:"cdrom_adapter_type" required:"false"`
// The guest OS type being installed. This will be
// set in the VMware VMX. By default this is other. By specifying a more
// specific OS type, VMware may perform some optimizations or virtual hardware
// changes to better support the operating system running in the
// virtual machine. Valid values differ by platform and version numbers, and may
// not match other VMware API's representation of the guest OS names. Consult your
// platform for valid values.
// The guest operating system identifier for the virtual machine.
// Defaults to `other`.
GuestOSType string `mapstructure:"guest_os_type" required:"false"`
// The [vmx hardware
// version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
// for the new virtual machine. Only the default value has been tested, any
// other value is experimental. Default value is `9`.
Version string `mapstructure:"version" required:"false"`
// This is the name of the VMX file for the new virtual
// machine, without the file extension. By default this is packer-BUILDNAME,
// where "BUILDNAME" is the name of the build.
// The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
// for more information on supported virtual hardware versions.
// Minimum is 13. Default is 19.
Version int `mapstructure:"version" required:"false"`
// The name of the virtual machine. This represents the name of the virtual
// machine `.vmx` configuration file without the file extension.
// Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
// build.
VMName string `mapstructure:"vm_name" required:"false"`

// The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
// for defining the contents of a virtual machine `.vmx` configuration file
// for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
// `{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
// the template.
//
// ~> **Note:** This option is intended for advanced users, as incorrect
// configurations can lead to non-functional virtual machines.
VMXDiskTemplatePath string `mapstructure:"vmx_disk_template_path"`
// Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
// defines the contents of the virtual machine VMX file for VMware. The
// engine has access to the template variables `{{ .DiskNumber }}` and
// `{{ .DiskName }}`.
// The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
// for defining the contents of a virtual machine `.vmx` configuration file.
//
// This is for **advanced users only** as this can render the virtual machine
// non-functional. See below for more information. For basic VMX
// modifications, try `vmx_data` first.
// ~> **Note:** This option is intended for advanced users, as incorrect
// configurations can lead to non-functional virtual machines. For simpler
// modifications of the virtual machine`.vmx` configuration file, consider
// using `vmx_data` option.
VMXTemplatePath string `mapstructure:"vmx_template_path" required:"false"`
// This is the name of the initial snapshot created after provisioning and cleanup.
// if left blank, no initial snapshot will be created
// The name of the virtual machine snapshot to be created.
// If this field is left empty, no snapshot will be created.
SnapshotName string `mapstructure:"snapshot_name" required:"false"`
// Enable virtual hardware-assisted virtualization for the virtual machine.
// Defaults to `false`.
Expand Down Expand Up @@ -156,8 +158,10 @@ func (c *Config) Prepare(raws ...interface{}) ([]string, error) {
c.VMName = fmt.Sprintf("packer-%s", c.PackerBuildName)
}

if c.Version == "" {
c.Version = "9"
if c.Version == 0 {
c.Version = defaultHardwareVersion
} else if c.Version < minimumHardwareVersion {
errs = packer.MultiErrorAppend(errs, fmt.Errorf("invalid 'version' %d, minimum hardware version: %d", c.Version, minimumHardwareVersion))
}

if c.VMXTemplatePath != "" {
Expand Down
4 changes: 2 additions & 2 deletions builder/vmware/iso/config.hcl2spec.go

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

13 changes: 6 additions & 7 deletions builder/vmware/iso/step_create_vmx.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ func (s *stepCreateVMX) Run(ctx context.Context, state multistep.StateBag) multi

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

templateData := vmxTemplateData{
Name: config.VMName,
GuestOS: config.GuestOSType,
DiskName: config.DiskName,
Version: config.Version,
ISOPath: isoPath,

Name: config.VMName,
GuestOS: config.GuestOSType,
DiskName: config.DiskName,
Version: strconv.Itoa(config.Version),
ISOPath: isoPath,
Network_Adapter: "e1000",

Sound_Present: map[bool]string{true: "TRUE", false: "FALSE"}[config.HWConfig.Sound],
Expand Down
75 changes: 36 additions & 39 deletions docs-partials/builder/vmware/iso/Config-not-required.mdx
Original file line number Diff line number Diff line change
@@ -1,46 +1,43 @@
<!-- Code generated from the comments of the Config struct in builder/vmware/iso/config.go; DO NOT EDIT MANUALLY -->

- `disk_size` (uint) - The size of the hard disk for the VM in megabytes.
The builder uses expandable, not fixed-size virtual hard disks, so the
actual file representing the disk will not use the full size unless it
is full. By default this is set to 40000 (about 40 GB).

- `cdrom_adapter_type` (string) - The adapter type (or bus) that will be used
by the cdrom device. This is chosen by default based on the disk adapter
type. VMware tends to lean towards ide for the cdrom device unless
sata is chosen for the disk adapter and so Packer attempts to mirror
this logic. This field can be specified as either ide, sata, or scsi.

- `guest_os_type` (string) - The guest OS type being installed. This will be
set in the VMware VMX. By default this is other. By specifying a more
specific OS type, VMware may perform some optimizations or virtual hardware
changes to better support the operating system running in the
virtual machine. Valid values differ by platform and version numbers, and may
not match other VMware API's representation of the guest OS names. Consult your
platform for valid values.

- `version` (string) - The [vmx hardware
version](http://kb.vmware.com/selfservice/microsites/search.do?language=en_US&cmd=displayKC&externalId=1003746)
for the new virtual machine. Only the default value has been tested, any
other value is experimental. Default value is `9`.

- `vm_name` (string) - This is the name of the VMX file for the new virtual
machine, without the file extension. By default this is packer-BUILDNAME,
where "BUILDNAME" is the name of the build.

- `vmx_disk_template_path` (string) - VMX Disk Template Path

- `vmx_template_path` (string) - Path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine) that
defines the contents of the virtual machine VMX file for VMware. The
engine has access to the template variables `{{ .DiskNumber }}` and
`{{ .DiskName }}`.
- `disk_size` (uint) - The size of the disk in megabytes. The builder uses expandable virtual
hard disks. The file that backs the virtual disk will only grow as needed
up to this size. Default is 40000 (~40 GB).

- `cdrom_adapter_type` (string) - The type of controller to use for the CD-ROM device.
Allowed values are `ide`, `sata`, and `scsi`.

- `guest_os_type` (string) - The guest operating system identifier for the virtual machine.
Defaults to `other`.

- `version` (int) - The virtual machine hardware version. Refer to [KB 315655](https://knowledge.broadcom.com/external/article?articleNumber=315655)
for more information on supported virtual hardware versions.
Minimum is 13. Default is 19.

- `vm_name` (string) - The name of the virtual machine. This represents the name of the virtual
machine `.vmx` configuration file without the file extension.
Default is `packer-<BUILDNAME>`, where `<BUILDNAME>` is the name of the
build.

- `vmx_disk_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
for defining the contents of a virtual machine `.vmx` configuration file
for a virtual disk. Template variables `{{ .DiskType }}`, `{{ .DiskUnit }}`,
`{{ .DiskName }}`, and `{{ .DiskNumber }}` are available for use within
the template.

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

- `snapshot_name` (string) - This is the name of the initial snapshot created after provisioning and cleanup.
if left blank, no initial snapshot will be created
- `vmx_template_path` (string) - The path to a [configuration template](/packer/docs/templates/legacy_json_templates/engine)
for defining the contents of a virtual machine `.vmx` configuration file.

~> **Note:** This option is intended for advanced users, as incorrect
configurations can lead to non-functional virtual machines. For simpler
modifications of the virtual machine`.vmx` configuration file, consider
using `vmx_data` option.

- `snapshot_name` (string) - The name of the virtual machine snapshot to be created.
If this field is left empty, no snapshot will be created.

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

0 comments on commit 330dc55

Please sign in to comment.