mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-02 03:22:59 +00:00
Add mac_addresses attribute to VM resource
This commit is contained in:
parent
1dfe979e9e
commit
d29a0a7ef6
@ -428,6 +428,7 @@ This resource doesn't expose any additional attributes.
|
|||||||
###### Attributes
|
###### Attributes
|
||||||
* `ipv4_addresses` - The IPv4 addresses per network interface published by the QEMU agent (empty list when `agent.enabled` is `false`)
|
* `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`)
|
* `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`)
|
* `network_interface_names` - The network interface names published by the QEMU agent (empty list when `agent.enabled` is `false`)
|
||||||
|
|
||||||
## Developing the Provider
|
## Developing the Provider
|
||||||
|
@ -77,6 +77,10 @@ output "resource_proxmox_virtual_environment_vm_example_ipv6_addresses" {
|
|||||||
value = "${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" {
|
output "resource_proxmox_virtual_environment_vm_example_network_interface_names" {
|
||||||
value = "${proxmox_virtual_environment_vm.example.network_interface_names}"
|
value = "${proxmox_virtual_environment_vm.example.network_interface_names}"
|
||||||
}
|
}
|
||||||
|
@ -1095,6 +1095,7 @@ func (r *CustomNetworkDevice) UnmarshalJSON(b []byte) error {
|
|||||||
r.Trunks[i] = iv
|
r.Trunks[i] = iv
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
|
r.MACAddress = &v[1]
|
||||||
r.Model = v[0]
|
r.Model = v[0]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,7 @@ const (
|
|||||||
mkResourceVirtualEnvironmentVMIPv4Addresses = "ipv4_addresses"
|
mkResourceVirtualEnvironmentVMIPv4Addresses = "ipv4_addresses"
|
||||||
mkResourceVirtualEnvironmentVMIPv6Addresses = "ipv6_addresses"
|
mkResourceVirtualEnvironmentVMIPv6Addresses = "ipv6_addresses"
|
||||||
mkResourceVirtualEnvironmentVMKeyboardLayout = "keyboard_layout"
|
mkResourceVirtualEnvironmentVMKeyboardLayout = "keyboard_layout"
|
||||||
|
mkResourceVirtualEnvironmentVMMACAddresses = "mac_addresses"
|
||||||
mkResourceVirtualEnvironmentVMMemory = "memory"
|
mkResourceVirtualEnvironmentVMMemory = "memory"
|
||||||
mkResourceVirtualEnvironmentVMMemoryDedicated = "dedicated"
|
mkResourceVirtualEnvironmentVMMemoryDedicated = "dedicated"
|
||||||
mkResourceVirtualEnvironmentVMMemoryFloating = "floating"
|
mkResourceVirtualEnvironmentVMMemoryFloating = "floating"
|
||||||
@ -515,6 +516,12 @@ func resourceVirtualEnvironmentVM() *schema.Resource {
|
|||||||
Default: dvResourceVirtualEnvironmentVMKeyboardLayout,
|
Default: dvResourceVirtualEnvironmentVMKeyboardLayout,
|
||||||
ValidateFunc: getKeyboardLayoutValidator(),
|
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{
|
mkResourceVirtualEnvironmentVMMemory: &schema.Schema{
|
||||||
Type: schema.TypeList,
|
Type: schema.TypeList,
|
||||||
Description: "The memory allocation",
|
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.
|
// Compare the network devices to those stored in the state.
|
||||||
currentNetworkDeviceList := d.Get(mkResourceVirtualEnvironmentVMNetworkDevice).([]interface{})
|
currentNetworkDeviceList := d.Get(mkResourceVirtualEnvironmentVMNetworkDevice).([]interface{})
|
||||||
|
|
||||||
|
macAddresses := make([]interface{}, 8)
|
||||||
networkDeviceLast := -1
|
networkDeviceLast := -1
|
||||||
networkDeviceList := make([]interface{}, 8)
|
networkDeviceList := make([]interface{}, 8)
|
||||||
networkDeviceObjects := []*proxmox.CustomNetworkDevice{
|
networkDeviceObjects := []*proxmox.CustomNetworkDevice{
|
||||||
@ -1493,20 +1501,24 @@ func resourceVirtualEnvironmentVMRead(d *schema.ResourceData, m interface{}) err
|
|||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = nd.Enabled
|
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = nd.Enabled
|
||||||
|
|
||||||
if nd.MACAddress != nil {
|
if nd.MACAddress != nil {
|
||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = *nd.MACAddress
|
macAddresses[ni] = *nd.MACAddress
|
||||||
} else {
|
} else {
|
||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = ""
|
macAddresses[ni] = ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceMACAddress] = macAddresses[ni]
|
||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceModel] = nd.Model
|
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceModel] = nd.Model
|
||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs] = nd.Trunks
|
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceVLANIDs] = nd.Trunks
|
||||||
} else {
|
} else {
|
||||||
|
macAddresses[ni] = ""
|
||||||
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = false
|
networkDevice[mkResourceVirtualEnvironmentVMNetworkDeviceEnabled] = false
|
||||||
}
|
}
|
||||||
|
|
||||||
networkDeviceList[ni] = networkDevice
|
networkDeviceList[ni] = networkDevice
|
||||||
}
|
}
|
||||||
|
|
||||||
|
d.Set(mkResourceVirtualEnvironmentVMMACAddresses, macAddresses[0:len(currentNetworkDeviceList)])
|
||||||
|
|
||||||
if len(currentNetworkDeviceList) > 0 || networkDeviceLast > -1 {
|
if len(currentNetworkDeviceList) > 0 || networkDeviceLast > -1 {
|
||||||
d.Set(mkResourceVirtualEnvironmentVMNetworkDevice, networkDeviceList[0:networkDeviceLast+1])
|
d.Set(mkResourceVirtualEnvironmentVMNetworkDevice, networkDeviceList[0:networkDeviceLast+1])
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
testComputedAttributes(t, s, []string{
|
testComputedAttributes(t, s, []string{
|
||||||
mkResourceVirtualEnvironmentVMIPv4Addresses,
|
mkResourceVirtualEnvironmentVMIPv4Addresses,
|
||||||
mkResourceVirtualEnvironmentVMIPv6Addresses,
|
mkResourceVirtualEnvironmentVMIPv6Addresses,
|
||||||
|
mkResourceVirtualEnvironmentVMMACAddresses,
|
||||||
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -61,6 +62,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
mkResourceVirtualEnvironmentVMMemory,
|
mkResourceVirtualEnvironmentVMMemory,
|
||||||
mkResourceVirtualEnvironmentVMName,
|
mkResourceVirtualEnvironmentVMName,
|
||||||
mkResourceVirtualEnvironmentVMNetworkDevice,
|
mkResourceVirtualEnvironmentVMNetworkDevice,
|
||||||
|
mkResourceVirtualEnvironmentVMMACAddresses,
|
||||||
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
mkResourceVirtualEnvironmentVMNetworkInterfaceNames,
|
||||||
mkResourceVirtualEnvironmentVMOSType,
|
mkResourceVirtualEnvironmentVMOSType,
|
||||||
mkResourceVirtualEnvironmentVMPoolID,
|
mkResourceVirtualEnvironmentVMPoolID,
|
||||||
@ -79,6 +81,7 @@ func TestResourceVirtualEnvironmentVMSchema(t *testing.T) {
|
|||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
schema.TypeList,
|
schema.TypeList,
|
||||||
|
schema.TypeList,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeString,
|
schema.TypeString,
|
||||||
schema.TypeBool,
|
schema.TypeBool,
|
||||||
|
Loading…
Reference in New Issue
Block a user