hashicorp / packer-plugin-vsphere

Packer plugin for VMware vSphere Builder
https://www.packer.io/docs/builders/vsphere
Mozilla Public License 2.0
93 stars 91 forks source link

`vsphere-clone`: Support Template Files for Windows Sysprep #357

Closed aidanleuck closed 5 months ago

aidanleuck commented 6 months ago

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

The vSphere clone builder allows you to customize a Windows virtual machine by providing a windows_sysprep_file in the customize block. This works great assuming you have a sysprep file on disk with all values hydrated before a Packer build starts. I intended to use this block to join my virtual machine to the domain. Given the current implementation this would require me to check my domain admin username and password as well as machine credentials into source control. I suggest doing something similar to Terraform which uses windows_sysprep_text instead of a path to a sysprep file. An example customize block in Terraform is shown below.

// Example Terraform Configuration
resource "vsphere_virtual_machine" "vm" {
    // ... other configuration ...
    clone {
      // ... other configuration ...
      customize {
        // ... other configuration ...
        windows_sysprep_text = file("${path.module}/sysprep.xml")
      }
    }
}

Using a text option will support the existing use case as well as the use case I have proposed. You can use the file function to get the same functionality that windows_sysprep_file supports or you can use a templatefile() function to support my use case.

Use Case(s)

Allow dynamic rendering of a sysprep file with templatefile() function.

Potential configuration

Add a new field windows_sysprep_text (potentially mark windows_sysprep_file as a deprecated field and remove in an upcoming release)

customize {
  windows_syprep_text = <unattend xml content>
}

Potential References

https://registry.terraform.io/providers/hashicorp/vsphere/latest/docs/resources/virtual_machine https://github.com/hashicorp/packer-plugin-vsphere/blob/main/builder/vsphere/clone/step_customize.go#L196