@Monkadelic_D thanks for that additional detail. I still feel that I'm unsure of the type of construct you are looking for. Here is an example that allows each VM to have a single private network and as many DHCP connected networks (meaning mac is provided) as needed.
# variables.tf
variable "mac_network" {
type = string
}
# Map where key is VM hostname and value is list of MACs
variable "vm_network_macs" {
type = map(list(string))
default = {}
}
# terraform.tfvars
vm_network_macs = {
"lab-vm-00" = ["0a:c3:fd:8a:6e:5b"],
"lab-vm-01" = ["52:b2:f4:d7:d4:fe"],
"lab-vm-02" = ["62:94:26:63:dd:a2"],
}
vm.tf
resource "xenorchestra_vm" "vm" {
# The vm_network_macs contains a key for every VM hostname
count = length(keys(var.vm_network_macs))
name_label = keys(var.vm_network_macs)[count.index]
[ ... ]
# This creates a network for each mac address provided
dynamic "network" {
for_each = lookup(var.vm_network_macs, keys(var.vm_network_macs)[count.index])
iterator = mac_addr
content {
network_id = var.mac_network
mac_address = mac_addr.value
}
}
# This is the private network your VMs will be given
network {
network_id = data.xenorchestra_network.network.id
}
}
Here is what the plan of that looks like:
Terraform will perform the following actions:
# xenorchestra_vm.vm[0] will be created
+ resource "xenorchestra_vm" "vm" {
[ .. ]
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = "0a:c3:fd:8a:6e:5b"
+ network_id = "Your mac network"
}
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = (known after apply)
+ network_id = "6c4e1cdc-9fe0-0603-e53d-4790d1fce8dd"
}
}
# xenorchestra_vm.vm[1] will be created
+ resource "xenorchestra_vm" "vm" {
[ .. ]
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = "52:b2:f4:d7:d4:fe"
+ network_id = "Your mac network"
}
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = (known after apply)
+ network_id = "6c4e1cdc-9fe0-0603-e53d-4790d1fce8dd"
}
}
# xenorchestra_vm.vm[2] will be created
+ resource "xenorchestra_vm" "vm" {
[ ... ]
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = "62:94:26:63:dd:a2"
+ network_id = "Your mac network"
}
+ network {
+ device = (known after apply)
+ ipv4_addresses = (known after apply)
+ ipv6_addresses = (known after apply)
+ mac_address = (known after apply)
+ network_id = "6c4e1cdc-9fe0-0603-e53d-4790d1fce8dd"
}
}
Plan: 3 to add, 0 to change, 0 to destroy.
If that isn't what you are looking for, I hope that it helps to spark additional inspiration from what you've tried already.