Skip to content

fix: attach additional disks#372

Merged
JenGoldstrich merged 1 commit intomainfrom
fix/vmx-builder-attach-additional-disks
Sep 3, 2025
Merged

fix: attach additional disks#372
JenGoldstrich merged 1 commit intomainfrom
fix/vmx-builder-attach-additional-disks

Conversation

@tenthirtyam
Copy link
Copy Markdown
Collaborator

@tenthirtyam tenthirtyam commented Aug 20, 2025

Description

Adds StepAttachAdditionalDisks to the vmware-vmx builder, enabling attachment of additional disks.

Testing:

packer-plugin-vmware/example on  fix/vmx-builder-attach-additional-disks [!?] via 🐹 v1.23.11 
➜ packer build -var-file=pkrvars/debian/vmx-fusion-arm64.pkrvars.hcl build-vmx.pkr.hcl
vmware-vmx.debian: output will be in this color.

==> vmware-vmx.debian: Configuring output and export directories...
==> vmware-vmx.debian: Creating temporary RSA SSH key for instance...
==> vmware-vmx.debian: Creating virtual machine disks...
==> vmware-vmx.debian: Cloning source virtual machine...
==> vmware-vmx.debian: Attaching 2 additional disk(s)...
==> vmware-vmx.debian: Detected existing disk adapter type: sata
==> vmware-vmx.debian: Attached additional disk: disk-1.vmdk at sata0:2
==> vmware-vmx.debian: Attached additional disk: disk-2.vmdk at sata0:3
==> vmware-vmx.debian: Powering on virtual machine...
==> vmware-vmx.debian: Connecting to VNC...
==> vmware-vmx.debian: Waiting 10s for boot...
==> vmware-vmx.debian: Typing the boot command over VNC...
==> vmware-vmx.debian: Using SSH communicator to connect: 192.168.213.204
==> vmware-vmx.debian: Waiting for SSH to become available...
==> vmware-vmx.debian: Connected to SSH!
==> vmware-vmx.debian: Gracefully halting virtual machine...
==> vmware-vmx.debian: Waiting for clean up...
==> vmware-vmx.debian: Deleting unnecessary files...
==> vmware-vmx.debian: Deleting: builds/debian-vmx-arm64/debian-vmx-arm64.plist
==> vmware-vmx.debian: Deleting: builds/debian-vmx-arm64/debian-vmx-arm64.vmx.lck/M24984.lck
==> vmware-vmx.debian: Deleting: builds/debian-vmx-arm64/packer-debian.scoreboard
==> vmware-vmx.debian: Deleting: builds/debian-vmx-arm64/vmware.log
==> vmware-vmx.debian: Compacting all attached virtual disks...
==> vmware-vmx.debian: Compacting virtual disk 1
==> vmware-vmx.debian: Cleaning VMX prior to finishing up...
==> vmware-vmx.debian: Disabling VNC server...
==> vmware-vmx.debian: Skipping export of virtual machine...
Build 'vmware-vmx.debian' finished after 2 minutes 35 seconds.

==> Wait completed after 2 minutes 35 seconds

==> Builds finished. The artifacts of successful builds are:
--> vmware-vmx.debian: VM files in directory: builds/debian-vmx-arm64

packer-plugin-vmware/example on  fix/vmx-builder-attach-additional-disks [!?] via 🐹 v1.23.11 took 2m 36.1s 

Notice the following:

==> vmware-vmx.debian: Cloning source virtual machine...
==> vmware-vmx.debian: Attaching 2 additional disk(s)...
==> vmware-vmx.debian: Detected existing disk adapter type: sata
==> vmware-vmx.debian: Attached additional disk: disk-1.vmdk at sata0:2
==> vmware-vmx.debian: Attached additional disk: disk-2.vmdk at sata0:3

Which in the .vmx looks like:

sata0.pcislotnumber = "32"
sata0.present = "TRUE"
sata0:0.filename = "disk-cl1.vmdk"
sata0:0.present = "TRUE"
sata0:0.redo = ""
sata0:1.autodetect = "TRUE"
sata0:1.clientdevice = "TRUE"
sata0:1.devicetype = "cdrom-raw"
sata0:1.filename = "auto detect"
sata0:1.present = "TRUE"
sata0:2.filename = "disk-1.vmdk"    <---
sata0:2.present = "TRUE"            <---
sata0:2.redo = ""                   <---
sata0:3.filename = "disk-2.vmdk"    <---
sata0:3.present = "TRUE"            <---
sata0:3.redo = ""                   <---

And...

image

Acceptance Test: TestRun_AttachAdditional Disks_SkipsReservedUnit7

packer-plugin-vmware on  fix/vmx-builder-attach-additional-disks [!?] via 🐹 v1.23.11 
➜ go test -v ./builder/vmware/vmx -run TestRun_AttachAdditional
Disks_SkipsReservedUnit7
=== RUN   TestRun_AttachAdditionalDisks_SkipsReservedUnit7
2025/09/02 23:47:49 [INFO] Writing VMX to: /var/folders/89/7szw2xb93m5dylqgdt9d62bc0000gn/T/TestRun_AttachAdditionalDisks_SkipsReservedUnit7293697710/001/test.vmx
2025/09/02 23:47:49 ui: Attaching 2 additional disk(s)...
2025/09/02 23:47:49 ui: Detected existing disk adapter type: scsi
2025/09/02 23:47:49 ui: Attached additional disk: disk-1.vmdk at scsi0:8
2025/09/02 23:47:49 ui: Attached additional disk: disk-2.vmdk at scsi0:9
2025/09/02 23:47:49 [INFO] Writing VMX to: /var/folders/89/7szw2xb93m5dylqgdt9d62bc0000gn/T/TestRun_AttachAdditionalDisks_SkipsReservedUnit7293697710/001/test.vmx
--- PASS: TestRun_AttachAdditionalDisks_SkipsReservedUnit7 (0.00s)
PASS
ok      github.com/hashicorp/packer-plugin-vmware/builder/vmware/vmx   0.308s

Resolved Issues

Closes #119

Rollback Plan

Revert commit.

Changes to Security Controls

None.

@tenthirtyam tenthirtyam added this to the v2.y.z milestone Aug 20, 2025
@tenthirtyam tenthirtyam self-assigned this Aug 20, 2025
@tenthirtyam tenthirtyam added the refactor Refactor label Aug 20, 2025
@tenthirtyam tenthirtyam force-pushed the fix/vmx-builder-attach-additional-disks branch 5 times, most recently from bca40b1 to 26658cd Compare August 28, 2025 23:38
@tenthirtyam tenthirtyam force-pushed the fix/vmx-builder-attach-additional-disks branch 3 times, most recently from 772dcd5 to dd24663 Compare September 3, 2025 03:32
@tenthirtyam tenthirtyam modified the milestones: v2.y.z, v2.0.0 Sep 3, 2025
@tenthirtyam tenthirtyam changed the title [wip] fix: attach additional disks fix: attach additional disks Sep 3, 2025
@tenthirtyam tenthirtyam force-pushed the fix/vmx-builder-attach-additional-disks branch from dd24663 to f4390a6 Compare September 3, 2025 03:48
@tenthirtyam tenthirtyam marked this pull request as ready for review September 3, 2025 03:49
@tenthirtyam tenthirtyam requested a review from a team as a code owner September 3, 2025 03:49
@tenthirtyam tenthirtyam added the builder/vmware-vmx Builder: vmware-vmx label Sep 3, 2025
@tenthirtyam tenthirtyam force-pushed the fix/vmx-builder-attach-additional-disks branch from f4390a6 to d03c522 Compare September 3, 2025 03:59
Adds `StepAttachAdditionalDisks` to the `vmware-vmx` builder, enabling attachment of additional disks.

Signed-off-by: Ryan Johnson <ryan.johnson@broadcom.com>
@tenthirtyam tenthirtyam force-pushed the fix/vmx-builder-attach-additional-disks branch from d03c522 to 9fd25d0 Compare September 3, 2025 04:00
ui := state.Get("ui").(packersdk.Ui)
vmxPath := state.Get("vmx_path").(string)

if len(config.AdditionalDiskSize) == 0 {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like there's two patterns here for skipping steps often, either adding a check into the step at the top level, like you do here, or in the builder only adding the step if its necessary. I tend to prefer having that complexity live in the builder, and having simpler steps. This is a balancing act though as you can end up with a builder with too many concerns: https://github.com/hashicorp/packer-plugin-azure/blob/main/builder/azure/arm/builder.go like the Azure ARM builder.

I wouldn't change this here, but I would just be aware of these trade-offs, and make a consistent choice

@JenGoldstrich JenGoldstrich merged commit 5a361a7 into main Sep 3, 2025
14 checks passed
@JenGoldstrich JenGoldstrich deleted the fix/vmx-builder-attach-additional-disks branch September 3, 2025 18:30
@github-actions
Copy link
Copy Markdown

I'm going to lock this pull request because it has been closed for 30 days. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 29, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

builder/vmware-vmx Builder: vmware-vmx refactor Refactor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

vmware-vmx: builder not attaching additional disks

2 participants