From 029dc1fb0adaf60db23956b3d558a6709e3ec4dc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oto=20Pet=C5=99=C3=ADk?= Date: Mon, 15 Aug 2022 03:23:41 +0200 Subject: [PATCH] Wait for 'net.IsGlobalUnicast' IP address (#115) VM can get IPv6 link-local address faster than a DHCP server response, that results in 'ipv4_addresses' output being an empty list. It is then impossible to provision the VM using 'connection.host' field derived from 'self.ipv4_addresses'. Change the waiting for IP address to ignore IPv4 link-local addresses and IPv6 link-local addresses. --- proxmox/virtual_environment_vm.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/proxmox/virtual_environment_vm.go b/proxmox/virtual_environment_vm.go index bc48c00c..2e32a4e5 100644 --- a/proxmox/virtual_environment_vm.go +++ b/proxmox/virtual_environment_vm.go @@ -9,6 +9,7 @@ import ( "errors" "fmt" "github.com/hashicorp/terraform-plugin-log/tflog" + "net" "net/url" "strings" "sync" @@ -406,6 +407,18 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(ctx conte missingIP = true break } + + hasGlobalUnicast := false + for _, addr := range *nic.IPAddresses { + if ip := net.ParseIP(addr.Address); ip != nil && ip.IsGlobalUnicast() { + hasGlobalUnicast = true + } + } + if !hasGlobalUnicast { + missingIP = true + break + } + } }