diff --git a/.web-docs/components/builder/iso/README.md b/.web-docs/components/builder/iso/README.md index 9b2d16cf..cc078734 100644 --- a/.web-docs/components/builder/iso/README.md +++ b/.web-docs/components/builder/iso/README.md @@ -78,47 +78,44 @@ necessary for this build to succeed and can be found further down the page. -- `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-`, where `` 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`. diff --git a/builder/vmware/iso/builder_test.go b/builder/vmware/iso/builder_test.go index 625639c8..0dc8dd78 100644 --- a/builder/vmware/iso/builder_test.go +++ b/builder/vmware/iso/builder_test.go @@ -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", @@ -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" { @@ -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) } } diff --git a/builder/vmware/iso/config.go b/builder/vmware/iso/config.go index ccb9815b..f441f562 100644 --- a/builder/vmware/iso/config.go +++ b/builder/vmware/iso/config.go @@ -15,6 +15,7 @@ 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" @@ -22,6 +23,10 @@ import ( 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"` @@ -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-`, where `` 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`. @@ -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 != "" { diff --git a/builder/vmware/iso/config.hcl2spec.go b/builder/vmware/iso/config.hcl2spec.go index b66c63b1..6bdffa79 100644 --- a/builder/vmware/iso/config.hcl2spec.go +++ b/builder/vmware/iso/config.hcl2spec.go @@ -144,7 +144,7 @@ type FlatConfig struct { DiskSize *uint `mapstructure:"disk_size" required:"false" cty:"disk_size" hcl:"disk_size"` CdromAdapterType *string `mapstructure:"cdrom_adapter_type" required:"false" cty:"cdrom_adapter_type" hcl:"cdrom_adapter_type"` GuestOSType *string `mapstructure:"guest_os_type" required:"false" cty:"guest_os_type" hcl:"guest_os_type"` - Version *string `mapstructure:"version" required:"false" cty:"version" hcl:"version"` + Version *int `mapstructure:"version" required:"false" cty:"version" hcl:"version"` VMName *string `mapstructure:"vm_name" required:"false" cty:"vm_name" hcl:"vm_name"` VMXDiskTemplatePath *string `mapstructure:"vmx_disk_template_path" cty:"vmx_disk_template_path" hcl:"vmx_disk_template_path"` VMXTemplatePath *string `mapstructure:"vmx_template_path" required:"false" cty:"vmx_template_path" hcl:"vmx_template_path"` @@ -298,7 +298,7 @@ func (*FlatConfig) HCL2Spec() map[string]hcldec.Spec { "disk_size": &hcldec.AttrSpec{Name: "disk_size", Type: cty.Number, Required: false}, "cdrom_adapter_type": &hcldec.AttrSpec{Name: "cdrom_adapter_type", Type: cty.String, Required: false}, "guest_os_type": &hcldec.AttrSpec{Name: "guest_os_type", Type: cty.String, Required: false}, - "version": &hcldec.AttrSpec{Name: "version", Type: cty.String, Required: false}, + "version": &hcldec.AttrSpec{Name: "version", Type: cty.Number, Required: false}, "vm_name": &hcldec.AttrSpec{Name: "vm_name", Type: cty.String, Required: false}, "vmx_disk_template_path": &hcldec.AttrSpec{Name: "vmx_disk_template_path", Type: cty.String, Required: false}, "vmx_template_path": &hcldec.AttrSpec{Name: "vmx_template_path", Type: cty.String, Required: false}, diff --git a/builder/vmware/iso/step_create_vmx.go b/builder/vmware/iso/step_create_vmx.go index d08e85a7..be51057d 100644 --- a/builder/vmware/iso/step_create_vmx.go +++ b/builder/vmware/iso/step_create_vmx.go @@ -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 @@ -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], diff --git a/docs-partials/builder/vmware/iso/Config-not-required.mdx b/docs-partials/builder/vmware/iso/Config-not-required.mdx index d923af75..989146f6 100644 --- a/docs-partials/builder/vmware/iso/Config-not-required.mdx +++ b/docs-partials/builder/vmware/iso/Config-not-required.mdx @@ -1,46 +1,43 @@ -- `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-`, where `` 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`.