Telmate / terraform-provider-proxmox

Terraform provider plugin for proxmox
MIT License
2.1k stars 509 forks source link

Duplicate mac address on two interfaces with cloud init processing #1000

Open Raumy opened 4 months ago

Raumy commented 4 months ago

Hello, Im' trying to create two VMs with a cloud init configuration. . I clone a template which has two network interfaces in the same bridge and in my configuration, I want to change the bridge for one interface. Telmat provider 3.0.1-rc1 Proxmox 8.1.4

Here is the configuration file:

locals {
  vm_name          = "server"
  pve_node         = "pve"
  iso_storage_pool = "local-lvm"
}

resource "proxmox_vm_qemu" "vm" {
    count = 2
    name      = "${local.vm_name}-vm-${count.index + 1}"
    vmid = 100 + count.index + 1
    target_node = local.pve_node

    agent = 1
    clone       = "template1"
    os_type     = "cloud-init"
    cores       = 1
    sockets     = 1
    memory      = 512
    bootdisk    = "scsi0"
    scsihw      = "virtio-scsi-pci"
    cloudinit_cdrom_storage = "local-lvm"
    full_clone  = true
    boot                    = "order=scsi0;ide3"

    disks {
        scsi {
            scsi0 {
                disk {
                    size               = 4
                    storage            = "local-lvm"
                }
            }
        }
    }

    network {
        bridge = "vmbr0"
        model = "virtio"
    }
    network {
        model  = "virtio"
        bridge = "analyse"  
    }

    ipconfig0 = "ip=192.168.37.${count.index + 150}/24,gw=192.168.37.2"
    ipconfig1 = "ip=172.27.0.${count.index + 150}/24,gw=172.27.0.254"

    cicustom = "user=local:snippets/userconfig.yaml"
}

When the second VM is instantiated, the network interfaces have a different mac address but when the second interface switches to another bridge, it recovers the same mac address as the other interface, in fact the machine is unreachable and the creation process is in a loop.

Before changing the bridge : prox_before

After changing the bridge :
prox_after

On the other hand, the first instantiated machine has two mac addresses and can be reached.

And we can see a cdrom drive on ide2 appears from nowhere....

Other information, when I instantiate only one machine, there is no problem, two different mac addresses, creation process which ends correctly.

Is there a way around the problem? Is this a configuration issue? A problem with the provider or with proxmox?

Thank you.

Tinyblargon commented 4 months ago

The ide2 will be fixed by RC2. The problem of getting duplicate MAC addresses is a bug. Don't know if it's in the Terraform code or in the underlying library.

Raumy commented 4 months ago

I've found a workaround by using terraform-provider-macaddress : provider.tf

terraform {
  required_providers {
    proxmox = {
        source = "telmate/proxmox"
        version="3.0.1-rc1"
    }
    macaddress = {
      source = "ivoronin/macaddress"
      version = "0.3.0"
    }
  }
}

And my main.tf

locals {
  vm_name          = "server"
  pve_node         = "pve"
  iso_storage_pool = "local-lvm"
}
resource "macaddress" "mac_address_analyse" {
    count = 2
}
resource "proxmox_vm_qemu" "vm" {
    count = 2
    name      = "${local.vm_name}-vm-${count.index + 1}"
    vmid = 100 + count.index + 1
    target_node = local.pve_node

    agent = 1
    clone       = "template1"
    os_type     = "cloud-init"
    cores       = 1
    sockets     = 1
    memory      = 512
    bootdisk    = "scsi0"
    scsihw      = "virtio-scsi-pci"
    cloudinit_cdrom_storage = "local-lvm"

    boot                    = "order=scsi0;ide3"

    disks {
        scsi {
            scsi0 {
                disk {
                    size               = 4
                    storage            = "local-lvm"
                }
            }
        }
    }

    network {
        bridge = "vmbr0"
        model = "virtio"
    }
    network {
        model  = "virtio"
        bridge = "analyse"  
        macaddr = upper(macaddress.mac_address_analyse[count.index].address)
    }

     # Configuration des interfaces réseau
    ipconfig0 = "ip=192.168.37.${count.index + 150}/24,gw=192.168.37.2"
    ipconfig1 = "ip=172.27.0.${count.index + 150}/24,gw=172.27.0.254"

    # Configuration du fichier cloud-init
    cicustom = "user=local:snippets/userconfig.yaml"

}

The "apply" process terminate with "Apply complete!" and all VMs are reacheable.

Tinyblargon commented 2 months ago

https://github.com/Telmate/proxmox-api-go/issues/341