hashicorp / packer-plugin-hyperv

Packer plugin for Hyper-V Builder
https://www.packer.io/docs/builders/hyperv
Mozilla Public License 2.0
19 stars 24 forks source link

GetHostAdapterIpAddressForSwitch returns wrong IP address #104

Open aaaallan opened 1 year ago

aaaallan commented 1 year ago

GetHostAdapterIpAddressForSwitch is returning an IP address that is incapable of acting as a server.

On one Hyper-V server, it's returning the IP of the iSCSI adapter, which has no gateway and cannot be used as a server. On another server it's returning a 169 address.

The problem seems to be with this on line 42 of hyperv.go. $HostNetAdapterConfiguration = @(Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $HostNetAdapter.InterfaceIndex | Where-Object SuffixOrigin -notmatch "Link")

This results in the build waiting forever at - ==> hyperv-iso.vm: Waiting for SSH to become available...

This may be a problem for any server that doesn't return the appropriate interface as the first result for this powershell command. Get-NetIPAddress -AddressFamily IPv4 -InterfaceIndex $HostNetAdapter.InterfaceIndex | Where-Object SuffixOrigin -notmatch "Link"

Packer version 1.9.1 hyperv-iso version v1.1.0_x5.0 - that's what I see in the exe filename. Installed via 'packer plugins install github.com/hashicorp/hyperv'.

Running on Windows Server 2019

If interfaces that did not have a gateway were excluded, the problem would be resolved. Get-NetIPAddress does not provide a way to see the gateway unfortunately. I'm wondering if a better solution is to provide a way to set an override variable like http_interface or http_bind_address.