feat: add disk_format config with post-export disk conversion#176
Open
abdelhaleemahmed wants to merge 1 commit intohashicorp:mainfrom
Open
feat: add disk_format config with post-export disk conversion#176abdelhaleemahmed wants to merge 1 commit intohashicorp:mainfrom
abdelhaleemahmed wants to merge 1 commit intohashicorp:mainfrom
Conversation
Add a new `disk_format` config field to the virtualbox-iso builder that
allows specifying the output disk format (VDI, VMDK, VHD). Default
remains VDI (the format VirtualBox creates internally).
VBoxManage export always converts VDI to VMDK (hardcoded in VirtualBox
C++ source: ApplianceImplExport.cpp). When disk_format is set to a
non-VMDK format, the export step now converts the VMDK back to the
requested format using VBoxManage clonemedium, and updates the OVF
references accordingly.
Changes:
- builder/virtualbox/common/step_export.go: Add DiskFormat field to
StepExport, add convertExportedDisk() method that runs after
VBoxManage export to convert VMDK to the requested format
- builder/virtualbox/iso/builder.go: Add DiskFormat config field with
validation (VDI/VMDK/VHD), pass it to StepExport
- builder/virtualbox/iso/step_create_disk.go: Use config.DiskFormat
instead of hardcoded "VDI"
- builder/virtualbox/iso/builder.hcl2spec.go: Add DiskFormat to HCL2 spec
Usage:
source "virtualbox-iso" "example" {
disk_format = "VDI"
# ... other config
}
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
disk_formatconfiguration field to thevirtualbox-isobuilderVBoxManage export(which always produces VMDK), automatically converts to the requested format usingVBoxManage clonemediumProblem
VBoxManage exportalways converts VDI disks to VMDK — this is hardcoded in VirtualBox's C++ source (ApplianceImplExport.cpp). Users who want VDI output (for discard/compact support) have no way to get it from the builder.Solution
Rather than trying to bypass VBoxManage export, this PR adds a post-export conversion step:
VBoxManage exportruns normally → produces correct OVF + VMDKdisk_formatis not VMDK,convertExportedDisk()runs:VBoxManage clonemedium disk.vmdk disk.vdi --format VDI.vmdkreferences in the OVF to.vdiUsage
Default is VDI (unchanged from current behavior where VirtualBox creates VDI internally). When set to VMDK, no conversion occurs (existing behavior).
Changes
builder/virtualbox/common/step_export.go— AddedDiskFormatfield toStepExport, addedconvertExportedDisk()methodbuilder/virtualbox/iso/builder.go— AddedDiskFormatconfig field with validation, pass to StepExportbuilder/virtualbox/iso/step_create_disk.go— Useconfig.DiskFormatinstead of hardcoded"VDI"builder/virtualbox/iso/builder.hcl2spec.go— AddedDiskFormatto HCL2 specTest plan
disk_format = "VDI"— VDI in outputvagrant upimports and boots successfullydisk_format = "VMDK"— no conversion occurs🤖 Generated with Claude Code