diff --git a/README.md b/README.md index 89e82c44..7d0dfe32 100644 --- a/README.md +++ b/README.md @@ -428,6 +428,7 @@ This resource doesn't expose any additional attributes. ###### Attributes * `ipv4_addresses` - The IPv4 addresses per network interface published by the QEMU agent (empty list when `agent.enabled` is `false`) * `ipv6_addresses` - The IPv6 addresses per network interface published by the QEMU agent (empty list when `agent.enabled` is `false`) +* `mac_addresses` - The MAC addresses assigned to the network devices * `network_interface_names` - The network interface names published by the QEMU agent (empty list when `agent.enabled` is `false`) ## Developing the Provider diff --git a/example/resource_virtual_environment_vm.tf b/example/resource_virtual_environment_vm.tf index aeea83e4..27563a38 100644 --- a/example/resource_virtual_environment_vm.tf +++ b/example/resource_virtual_environment_vm.tf @@ -77,6 +77,10 @@ output "resource_proxmox_virtual_environment_vm_example_ipv6_addresses" { value = "${proxmox_virtual_environment_vm.example.ipv6_addresses}" } +output "resource_proxmox_virtual_environment_vm_example_mac_addresses" { + value = "${proxmox_virtual_environment_vm.example.mac_addresses}" +} + output "resource_proxmox_virtual_environment_vm_example_network_interface_names" { value = "${proxmox_virtual_environment_vm.example.network_interface_names}" } diff --git a/proxmox/virtual_environment_vm_types.go b/proxmox/virtual_environment_vm_types.go index 977a7b44..bd9c7eb4 100644 --- a/proxmox/virtual_environment_vm_types.go +++ b/proxmox/virtual_environment_vm_types.go @@ -1095,6 +1095,7 @@ func (r *CustomNetworkDevice) UnmarshalJSON(b []byte) error { r.Trunks[i] = iv } default: + r.MACAddress = &v[1] r.Model = v[0] } } diff --git a/proxmoxtf/resource_virtual_environment_vm.go b/proxmoxtf/resource_virtual_environment_vm.go index ecedf3f1..4caa91b5 100644 --- a/proxmoxtf/resource_virtual_environment_vm.go +++ b/proxmoxtf/resource_virtual_environment_vm.go @@ -92,6 +92,7 @@ const ( mkResourceVirtualEnvironmentVMIPv4Addresses = "ipv4_addresses" mkResourceVirtualEnvironmentVMIPv6Addresses = "ipv6_addresses" mkResourceVirtualEnvironmentVMKeyboardLayout = "keyboard_layout" + mkResourceVirtualEnvironmentVMMACAddresses = "mac_addresses" mkResourceVirtualEnvironmentVMMemory = "memory" mkResourceVirtualEnvironmentVMMemoryDedicated = "dedicated" mkResourceVirtualEnvironmentVMMemoryFloating = "floating" @@ -515,6 +516,12 @@ func resourceVirtualEnvironmentVM() *schema.Resource { Default: dvResourceVirtualEnvironmentVMKeyboardLayout, ValidateFunc: getKeyboardLayoutValidator(), }, + mkResourceVirtualEnvironmentVMMACAddresses: { + Type: schema.TypeList, + Computed: true, + Description: "The MAC addresses for the network interfaces", + Elem: &schema.Schema{Type: schema.TypeString}, + }, mkResourceVirtualEnvironmentVMMemory: &schema.Schema{ Type: schema.TypeList, Description: "The memory allocation", @@ -1465,6 +1472,7 @@ func resourceVirtualEnvironmentVMRead(d *schema.ResourceData, m interface{}) err // Compare the network devices to those stored in the state. currentNetworkDeviceList := d.Get(mkResourceVirtualEnvironmentVMNetworkDevice).([]interface{}) + macAddresses := make([]interface{}, 8) networkDeviceLast := -1 networkDeviceList := make([]interface{}, 8) networkDeviceObjects := []*proxmox.CustomNetworkDevice{ @@ -1493,20 +1501,24 @@ func resourceVirtualEnvironmentVMRead(d *schema.ResourceData, m interface{}) err networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = nd.Enabled if nd.MACAddress != nil { - networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = *nd.MACAddress + macAddresses[ni] = *nd.MACAddress } else { - networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = "" + macAddresses[ni] = "" } + networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = macAddresses[ni] networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceModel] = nd.Model networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs] = nd.Trunks } else { + macAddresses[ni] = "" networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = false } networkDeviceList[ni] = networkDevice } + d.Set(mkResourceVirtualEnvironmentVMMACAddresses, macAddresses[0:len(currentNetworkDeviceList)]) + if len(currentNetworkDeviceList) > 0 || networkDeviceLast > -1 { d.Set(mkResourceVirtualEnvironmentVMNetworkDevice, networkDeviceList[0:networkDeviceLast+1]) } diff --git a/proxmoxtf/resource_virtual_environment_vm_test.go b/proxmoxtf/resource_virtual_environment_vm_test.go index 85a9e068..0aaca079 100644 --- a/proxmoxtf/resource_virtual_environment_vm_test.go +++ b/proxmoxtf/resource_virtual_environment_vm_test.go @@ -46,6 +46,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) { testComputedAttributes(t, s, []string{ mkResourceVirtualEnvironmentVMIPv4Addresses, mkResourceVirtualEnvironmentVMIPv6Addresses, + mkResourceVirtualEnvironmentVMMACAddresses, mkResourceVirtualEnvironmentVMNetworkInterfaceNames, }) @@ -61,6 +62,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) { mkResourceVirtualEnvironmentVMMemory, mkResourceVirtualEnvironmentVMName, mkResourceVirtualEnvironmentVMNetworkDevice, + mkResourceVirtualEnvironmentVMMACAddresses, mkResourceVirtualEnvironmentVMNetworkInterfaceNames, mkResourceVirtualEnvironmentVMOSType, mkResourceVirtualEnvironmentVMPoolID, @@ -79,6 +81,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) { schema.TypeString, schema.TypeList, schema.TypeList, + schema.TypeList, schema.TypeString, schema.TypeString, schema.TypeBool,