From e15c4a678409a378ce10ed47fb73051e9dcdae61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oto=20Pet=C5=99=C3=ADk?= Date: Thu, 1 Jun 2023 03:12:27 +0200 Subject: [PATCH] fix(vm): Make mac_address computed, fix #339 (#354) Fields `network_interface_names`, `ipv4_addresses` and `ipv6_addresses` are sometimes be marked `computed` again, using `CustomizeDiff`. Changes in `VMStarted` or `VMNetworkDevice` attributes invalidate those values. Marking fields `computed` again avoids stale values. `network_device` configuration block without `mac_address` results in MAC address set to its default value (an empty string). Terraform state expects `mac_address` to be an empty string, server provides the actual (random) MAC address of the network device. Terraform detects there are changes to be made, but because of `DiffSuppressFunc` on `mac_address` they are hidden from the user, but not from d.HasChange(mkResourceVirtualEnvironmentVMNetworkDevice) By making `mac_address` also `computed`, the server-generated MAC address is stored locally, avoiding spurious changes that trigger re-computation of `network_interface_names`, `ipv4_addresses` and `ipv6_addresses`. --- proxmoxtf/resource/vm.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/proxmoxtf/resource/vm.go b/proxmoxtf/resource/vm.go index 570b1906..56308777 100644 --- a/proxmoxtf/resource/vm.go +++ b/proxmoxtf/resource/vm.go @@ -84,7 +84,6 @@ const ( dvResourceVirtualEnvironmentVMNetworkDeviceBridge = "vmbr0" dvResourceVirtualEnvironmentVMNetworkDeviceEnabled = true dvResourceVirtualEnvironmentVMNetworkDeviceFirewall = false - dvResourceVirtualEnvironmentVMNetworkDeviceMACAddress = "" dvResourceVirtualEnvironmentVMNetworkDeviceModel = "virtio" dvResourceVirtualEnvironmentVMNetworkDeviceRateLimit = 0 dvResourceVirtualEnvironmentVMNetworkDeviceVLANID = 0 @@ -994,13 +993,10 @@ func VM() *schema.Resource { Default: dvResourceVirtualEnvironmentVMNetworkDeviceFirewall, }, mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress: { - Type: schema.TypeString, - Description: "The MAC address", - Optional: true, - Default: dvResourceVirtualEnvironmentVMNetworkDeviceMACAddress, - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - return new == "" - }, + Type: schema.TypeString, + Description: "The MAC address", + Optional: true, + Computed: true, ValidateDiagFunc: getMACAddressValidator(), }, mkResourceVirtualEnvironmentVMNetworkDeviceModel: {