From 722e01053bdb51c038a7bd86d4018465417ea6fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Szczepan=20Wi=C5=9Bniowski?= Date: Sun, 11 Dec 2022 22:29:25 +0100 Subject: [PATCH] fix: Check if any interface has global unicast address instead of all interfaces (#182) * fix: Check if any interface has global unicast address instead of all interfaces This allows us to have multiple interfaces and only one (instead of all) has to have assigned ip * add multiple network devices to the example VM Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --- example/resource_virtual_environment_vm.tf | 4 ++++ proxmox/virtual_environment_vm.go | 11 +++-------- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/example/resource_virtual_environment_vm.tf b/example/resource_virtual_environment_vm.tf index e06284b3..720cb21e 100644 --- a/example/resource_virtual_environment_vm.tf +++ b/example/resource_virtual_environment_vm.tf @@ -41,6 +41,10 @@ resource "proxmox_virtual_environment_vm" "example_template" { network_device {} + network_device { + vlan_id = 1024 + } + node_name = data.proxmox_virtual_environment_nodes.example.names[0] operating_system { diff --git a/proxmox/virtual_environment_vm.go b/proxmox/virtual_environment_vm.go index 52a004e8..dcafac65 100644 --- a/proxmox/virtual_environment_vm.go +++ b/proxmox/virtual_environment_vm.go @@ -396,6 +396,7 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(ctx conte if err == nil && data != nil && data.Result != nil { missingIP := false + hasAnyGlobalUnicast := false if waitForIP { for _, nic := range *data.Result { @@ -408,21 +409,15 @@ func (c *VirtualEnvironmentClient) WaitForNetworkInterfacesFromVMAgent(ctx conte break } - hasGlobalUnicast := false for _, addr := range *nic.IPAddresses { if ip := net.ParseIP(addr.Address); ip != nil && ip.IsGlobalUnicast() { - hasGlobalUnicast = true + hasAnyGlobalUnicast = true } } - if !hasGlobalUnicast { - missingIP = true - break - } - } } - if !missingIP { + if hasAnyGlobalUnicast || !missingIP { return data, err } }