Skip to content

feat: attach tools iso#386

Merged
kp2099 merged 1 commit intomainfrom
feat/attach-tools-iso
Oct 7, 2025
Merged

feat: attach tools iso#386
kp2099 merged 1 commit intomainfrom
feat/attach-tools-iso

Conversation

@tenthirtyam
Copy link
Copy Markdown
Collaborator

@tenthirtyam tenthirtyam commented Sep 17, 2025

Description

Caution

This is a breaking change and will be shipped in v2.

This pull request introduces a new mechanism for providing VMware Tools to virtual machines, adding support for explicit modes (upload, attach, and disable) and refactoring the configuration and implementation accordingly. It also adds robust logic for attaching VMware Tools ISO as a CD-ROM device, including slot detection and device management, and updates documentation to reflect these changes.

  • Added explicit tools_mode configuration supporting three modes: upload (uploads ISO), attach (attaches ISO as CD-ROM), and disable (no ISO provided). This change is reflected in both documentation files (.web-docs/components/builder/iso/README.md and .web-docs/components/builder/vmx/README.md) and in code constants (builder/vmware/common/driver.go). [1] [2] [3] [4]
  • Added new utility functions in cdrom_utils.go to find the next available CD-ROM slot, attach, and detach CD-ROM devices in VMX configuration data, supporting IDE, SATA, and SCSI adapters.
  • Implemented StepAttachToolsCDROM, a new build step that attaches the VMware Tools ISO as a CD-ROM device based on configuration, handling device slot selection, error cases, and state management.
  • Added comprehensive unit tests for the new step, covering all major scenarios: skipping when not in attach mode, handling missing ISO, successful attachment, conflict resolution, default adapter type usage, VMX read errors, and cleanup.
  • Updated documentation for both ISO and VMX builders to describe the new tools_mode and clarify the usage and restrictions of related configuration options. [1] [2]

Valid Configurations

1. Upload Mode with Flavor
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "upload"
  tools_upload_flavor = "linux"
  tools_upload_path   = "/tmp/vmware-tools.iso"
}
2. Upload Mode with Flavor and Default Path
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "upload"
  tools_upload_flavor = "windows"
}
3. Upload Mode with Custom ISO File
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "upload"
  tools_source_path = "/path/to/vmware-tools.iso"
  tools_upload_path = "/tmp/custom-tools.iso"
}
4. Attach Mode with Local ISO
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "attach"
  tools_source_path = "/path/to/vmware-tools.iso"
}
5. Disabled Tools
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode = "disable"
}
6. Upload Mode with Template Path
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "upload"
  tools_upload_flavor = "windows"
  tools_upload_path   = "/Users/packer/Downloads/{{ .Flavor }}-vmware-tools.iso"
}

Invalid Configurations

1. Missing tools_mode (when using tools config)
# ❌ INVALID: tools_mode must be explicitly specified
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_upload_flavor = "windows"  # Error: requires tools_mode
}

Error: 'tools_mode' must be explicitly specified when using any tools configuration

2. Invalid tools_mode value
# ❌ INVALID: invalid tools_mode
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode = "invalid_mode"
}

Error: invalid 'tools_mode' specified: invalid_mode; must be one of upload, attach, disable

3. Invalid tools_upload_flavor
# ❌ INVALID: invalid flavor
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "upload"
  tools_upload_flavor = "invalid_os"
}

Error: invalid 'tools_upload_flavor' specified: invalid_os; must be one of darwin, linux, windows

4. Conflicting upload configuration
# ❌ INVALID: cannot use both flavor and source path
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "upload"
  tools_upload_flavor = "linux"
  tools_source_path   = "/path/to/tools.iso"  # Conflict!
}

Error: 'tools_upload_flavor' and 'tools_source_path' cannot both be specified - use one or the other

5. Upload mode without source
# ❌ INVALID: upload mode needs either flavor or source path
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode = "upload"
  # Missing: tools_upload_flavor OR tools_source_path
}

Error: 'tools_mode="upload"' requires either 'tools_upload_flavor' or 'tools_source_path'

6. Attach mode without source path
# ❌ INVALID: attach mode requires source path
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode = "attach"
  # Missing: tools_source_path
}

Error: 'tools_source_path' is required when 'tools_mode="attach"'

7. Upload path with attach mode
# ❌ INVALID: upload path only works with upload mode
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "attach"
  tools_source_path = "/path/to/tools.iso"
  tools_upload_path = "/tmp/tools.iso"  # Invalid with attach mode
}

Error: 'tools_upload_path' can only be used with 'tools_mode="upload"', not 'tools_mode="attach"'

8. Non-existent source path
# ❌ INVALID: source file doesn't exist
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "attach"
  tools_source_path = "/nonexistent/path/tools.iso"
}

Error: tools source path does not exist: /nonexistent/path/tools.iso

9. Relative path (not absolute)
# ❌ INVALID: path must be absolute
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "attach"
  tools_source_path = "relative/path/tools.iso"
}

Error: tools source path must be absolute, got relative path: relative/path/tools.iso

10. Directory instead of file
# ❌ INVALID: source path points to directory
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode        = "attach"
  tools_source_path = "/Applications/VMware Fusion.app"  # Directory, not file
}

Error: tools source path must be a file, not a directory: /Applications/VMware Fusion.app

Warnings

1. Ignored configuration with disabled mode
# ⚠️ WARNING: extra config ignored
source "vmware-iso" "example" {
  # ... other configuration ...

  tools_mode          = "disable"
  tools_upload_flavor = "linux"      # Ignored
  tools_upload_path   = "/tmp/tools"  # Ignored
  tools_source_path   = "/path/tools" # Ignored
}

Warnings:

  • 'tools_upload_flavor' is ignored when 'tools_mode="disable"'
  • 'tools_upload_path' is ignored when 'tools_mode="disable"'
  • 'tools_source_path' is ignored when 'tools_mode="disable"'

Resolved Issues

Closes #281

Rollback Plan

Revert commit.

Changes to Security Controls

None.

@tenthirtyam tenthirtyam added this to the v2.0.0 milestone Sep 17, 2025
@tenthirtyam tenthirtyam self-assigned this Sep 17, 2025
@tenthirtyam tenthirtyam added enhancement Enhancement breaking-change Breaking Change labels Sep 17, 2025
@tenthirtyam tenthirtyam requested a review from kp2099 September 17, 2025 00:42
@tenthirtyam tenthirtyam marked this pull request as ready for review September 17, 2025 01:11
@tenthirtyam tenthirtyam requested a review from a team as a code owner September 17, 2025 01:11
@tenthirtyam tenthirtyam force-pushed the feat/attach-tools-iso branch 3 times, most recently from ddc3db5 to 00c018f Compare September 17, 2025 01:24
@tenthirtyam
Copy link
Copy Markdown
Collaborator Author

Ready for review, @kp2099!

@kp2099
Copy link
Copy Markdown
Contributor

kp2099 commented Oct 6, 2025

@tenthirtyam, it looks like there are merge conflicts here since I merged the Usb version PR before this one. Could you please resolve them?

Copilot AI review requested due to automatic review settings October 6, 2025 13:15
@tenthirtyam tenthirtyam force-pushed the feat/attach-tools-iso branch from 00c018f to cf7293b Compare October 6, 2025 13:15
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a new tools mode system for VMware virtual machines, adding explicit control over how VMware Tools ISO files are provided to VMs. The key change is the introduction of a tools_mode configuration parameter that supports three modes: upload (uploads ISO), attach (attaches ISO as CD-ROM), and disable (no ISO provided).

Key changes:

  • Added new tools_mode configuration with validation and mode-specific behavior
  • Implemented CD-ROM attachment functionality for the new "attach" mode
  • Enhanced build steps to support both upload and attach workflows with proper cleanup

Reviewed Changes

Copilot reviewed 22 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
docs-partials/builder/vmware/common/ToolsConfig-not-required.mdx Updated documentation to reflect new tools_mode configuration and parameter reorganization
builder/vmware/common/tools_config.go Added tools_mode validation, mode-specific logic, and comprehensive parameter validation
builder/vmware/common/step_attach_tools_cdrom.go New step implementation for attaching VMware Tools ISO as CD-ROM device
builder/vmware/common/cdrom_utils.go New utility functions for CD-ROM device slot management and attachment/detachment
builder/vmware/common/step_clean_vmx.go Enhanced VMX cleanup to properly handle tools CD-ROM device removal
builder/vmware/iso/builder.go Integration of new tools attach step in build pipeline
builder/vmware/vmx/builder.go Integration of new tools attach step in build pipeline

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

@tenthirtyam tenthirtyam force-pushed the feat/attach-tools-iso branch from cf7293b to 4d8e718 Compare October 6, 2025 13:19
Adds the option to attach VMware Tools ISO as a CD-ROM device. Adds `tools_mode` configuration for choosing between `upload`, `attach`, or `disable` modes.

Signed-off-by: Ryan Johnson <rya@tenthirtyam.org>
@tenthirtyam tenthirtyam force-pushed the feat/attach-tools-iso branch from 4d8e718 to 37e883d Compare October 6, 2025 13:22
@kp2099 kp2099 merged commit 3ece6db into main Oct 7, 2025
14 checks passed
@kp2099 kp2099 deleted the feat/attach-tools-iso branch October 7, 2025 06:33
@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

breaking-change Breaking Change enhancement Enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support to attach VMware Tools ISO for installation

3 participants