hashicorp / hashicorp/packer-plugin-vagrant

Please add Hyper-V configuration versions information in box.xml during vagrant post processor.

Open
#23 4 comments 2 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
16
Forks
28
PR merge metrics
No merged PRs in 30d

Description

_This issue was originally opened by @fsdrw08 in https://github.com/hashicorp/packer/issues/11129 and has been migrated to this repository. The original issue description is below._

---
#### Description

Please add Hyper-V configuration versions information in box.xml during vagrant post processor.
I found that even if we specify the configuration_version (https://www.packer.io/docs/builders/hyperv/iso#configuration_version) in packer template, with vagrant post-processor to build a vagrant box (which means as expect, it should be a lower configuration version Hyper-V VM box). But `Vagrant up` this box will still create a VM in hyper-V with the latest configuration version .

After investigate Vagrant's related HYPER-V VM create script, I found that Vagrant will primary use the information from box.xml (under .vagrant.d\boxes\ ``\0\hyperv\Virtual Machines) as VM parameter to create a new VM with PowerShell CMDLET `New-VM`. And if we don't specify the `-Version` (VM configuration version) parameter in this `New-VM` command, it will create the VM with the as latest as the host support version. e.g. in Win10 21H1, this command will create a 9.0 version VM without -version parameter.

My Request:

- First, in packer vagrant post processor part:
Add Hyper-V configuration versions information in box.xml during vagrant post processor.

- After first part, in vagrant up process part:
Improve vagrant hyper-v plug in script module "VagrantVM.psm" to let vagrant up a hyper-v vm box with it's own configuration version.

#### Use Case(s)

The purpose use case is `vagrant up` a Hyper-V VM box as what the box original configuration version is.

#### Potential configuration
- Add Hyper-V configuration versions information in box.xml during vagrant post processor. The expect result like
``
` `
` ...`
**` 8.0`**
` `
` ...`
``

- After box.xml improve, in `vagrant up` process part:
add some script snippet to detect the box xml version node in https://github.com/hashicorp/vagrant/blob/5b501a3fb05ed0ab16cf10991b3df9d231edb5cf/plugins/providers/hyperv/scripts/utils/VagrantVM/VagrantVM.psm1 's New-VagrantVMXML function
something like insert below code in line 241
`$Version = [string]($VMConfig.configuration.properties.version."#text")`
`# Version parameter in PS4 so validate before using`
` if((Get-Command Hyper-V\New-VM).Parameters.Keys.Contains("version")) {`
` $NewVMConfig.Version = $Version`
` }`

```
```

#### Potential References

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.