Skip to content

feat: add disk_format config with post-export disk conversion#176

Open
abdelhaleemahmed wants to merge 1 commit intohashicorp:mainfrom
abdelhaleemahmed:feature/post-export-disk-conversion
Open

feat: add disk_format config with post-export disk conversion#176
abdelhaleemahmed wants to merge 1 commit intohashicorp:mainfrom
abdelhaleemahmed:feature/post-export-disk-conversion

Conversation

@abdelhaleemahmed
Copy link
Copy Markdown

Summary

  • Adds a disk_format configuration field to the virtualbox-iso builder
  • Supports VDI, VMDK, and VHD output formats
  • After VBoxManage export (which always produces VMDK), automatically converts to the requested format using VBoxManage clonemedium
  • Updates OVF references to point to the new disk file

Problem

VBoxManage export always 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:

  1. VBoxManage export runs normally → produces correct OVF + VMDK
  2. If disk_format is not VMDK, convertExportedDisk() runs:
    • VBoxManage clonemedium disk.vmdk disk.vdi --format VDI
    • Updates .vmdk references in the OVF to .vdi
    • Deletes the VMDK

Usage

source "virtualbox-iso" "example" {
  disk_format = "VDI"
  # ... other config
}

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 — Added DiskFormat field to StepExport, added convertExportedDisk() method
  • builder/virtualbox/iso/builder.go — Added DiskFormat config field with validation, pass to StepExport
  • builder/virtualbox/iso/step_create_disk.go — Use config.DiskFormat instead of hardcoded "VDI"
  • builder/virtualbox/iso/builder.hcl2spec.go — Added DiskFormat to HCL2 spec

Test plan

  • Build Rocky Linux 9 box with disk_format = "VDI" — VDI in output
  • Verify OVF references updated correctly
  • Vagrant post-processor packages VDI into .box
  • vagrant up imports and boots successfully
  • Build with default (no disk_format) — existing behavior unchanged
  • Build with disk_format = "VMDK" — no conversion occurs

🤖 Generated with Claude Code

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>
@abdelhaleemahmed abdelhaleemahmed requested a review from a team as a code owner April 9, 2026 09:23
@hashicorp-cla-app
Copy link
Copy Markdown

hashicorp-cla-app bot commented Apr 9, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant