terraform-provider-proxmox: cloud-init no longer working.

Hi guys, I’ve been reading the issues and can’t get my head around the fix needed to be able to run cloudinit templates. Luckily by old system still works, but I’m trying to implement it on a second promox system and I guess since some update it has broken. Could anyone please give feedback on what I am doing wrong?

I was able to make it so it at least starts creating the VMs, but now I get the error “Boot failed: no bootable disk.” I can’t seem to figure out what I am doing wrong.

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

provider "proxmox" {
  # url is the hostname Add /api2/json at the end for the API
  pm_api_url = "http://198.18.202.11:8006/api2/json"

  # api token id is in the form of: <username>@pam!<tokenId>
  pm_api_token_id = "terraform@pam!new_token_id"

  # this is the full secret wrapped in quotes.
  pm_api_token_secret = "x"

  # leave tls_insecure set to true unless proxmox SSL
  pm_tls_insecure = true
}

variable "vm_configs" {
  description = "Configuration for VMs"
  type        = map

  default = {
    velociraptor = {
      name        = "velociraptor"
      memory      = 2048
      ip_address  = "198.18.202.210"
      cores       = 2
      storage     = "local-lvm"
      storage_size = "10G"
    },
    plaso = {
      name        = "plaso"
      memory      = 4096
      ip_address  = "198.18.202.211"
      cores       = 2
      storage     = "local-lvm"
      storage_size = "20G"
    }
    # Add other VM configurations as needed
  }
}

resource "proxmox_vm_qemu" "vms" {
  for_each = var.vm_configs

  name       = each.value["name"]
  target_node = var.proxmox_host
  clone       = var.template_name

  agent    = 1
  os_type  = "cloud-init"
  cores    = each.value["cores"]
  sockets  = 1
  cpu      = "host"
  memory   = each.value["memory"]
  scsihw   = "virtio-scsi-pci"
  bootdisk = "scsi0"

   disks {   
    virtio {
      virtio0 {
        disk {
          size            = 20
          cache           = "writeback"
          storage         = "local-lvm"
        }
      }
    }
  }

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

  lifecycle {
    ignore_changes = [
      network,
    ]
  }

  ipconfig0 = "ip=${each.value["ip_address"]}/24,gw=198.18.201.1"

  sshkeys = <<EOF
  ${var.ssh_key}
  EOF
}

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 22 (2 by maintainers)

Most upvoted comments

With this code, it works : proxmox_vm_qemu.tf :

resource "null_resource" "cloud_init_user_data_file" {
  connection {
    user        = "root"
    private_key = var.root_private_key
    host        = var.prx_node
    port        = 22
  }

  provisioner "file" {
    content = templatefile(
      "../files/cloud-init/cloud-init.cloud_config_user.tftpl",
      {
        hostname            = var.vm_name,
        user                = var.adm_username,
        password            = var.adm_pwd,
        ssh_authorized_keys = var.ssh_authorized_keys,
      }
    )
    destination = "/var/lib/vz/snippets/user_data_vm-${var.vm_name}.yml"
  }

  triggers = {
    hostname            = var.vm_name,
    user                = var.adm_username,
    ssh_authorized_keys = var.ssh_authorized_keys,
    password            = var.adm_pwd,
  }
}

resource "null_resource" "cloud_init_network_data_file" {
  connection {
    user        = "root"
    private_key = var.root_private_key
    host        = var.prx_node
    port        = 22
  }

  provisioner "file" {
    content = templatefile(
      "../files/cloud-init/cloud-init.cloud_config_network.tftpl",
      {
        ip_dns = var.ip_dns,
      }
    )
    destination = "/var/lib/vz/snippets/network_data_vm-${var.vm_name}.yml"
  }

  triggers = {
    ip_dns = var.ip_dns,
  }
}

resource "proxmox_vm_qemu" "main" {
  name                   = var.vm_name
  target_node            = var.prx_node
  clone                  = "cirocky9tpl"
  desc                   = "Rocky Linux 9 VM fully cloned from cirocky9tpl"
  agent                  = 1
  cores                  = 4
  define_connection_info = false
  force_create           = true
  memory                 = var.vm_memory
  onboot                 = true
  qemu_os                = "l26"
  scsihw                 = "virtio-scsi-single"

  disks {
    scsi {
      scsi0 {
        disk {
          size    = 50
          storage = "local"
          replicate            = true
        }
      }
    }
  }

  network {
    bridge  = "vmbr1"
    model   = "virtio"
    macaddr = var.vm_mac
  }

  os_type = "cloud-init"

  ciuser                = var.adm_username
  cipassword            = var.adm_pwd
  sshkeys = var.ssh_authorized_keys
  cloudinit_cdrom_storage = "local"
  cicustom = "user=local:snippets/user_data_vm-${var.vm_name}.yml,network=local:snippets/network_data_vm-${var.vm_name}.yml"

  provisioner "remote-exec" {
    connection {
      user                = var.adm_username
      private_key         = var.adm_private_key
      host                = self.name
      bastion_host        = var.bind_ip_address
      bastion_port        = var.bind_ssh_port
      bastion_user        = var.bind_ssh_user
      bastion_private_key = var.bind_ssh_private_key
    }
    inline = [
      "ip a"
    ]
  }

  depends_on = [
    null_resource.cloud_init_user_data_file,
    null_resource.cloud_init_network_data_file,
  ]

  lifecycle {
    replace_triggered_by = [
      null_resource.cloud_init_user_data_file,
      null_resource.cloud_init_network_data_file,
    ]
  }
}

cloud-init.cloud_config_user.tftpl :

#cloud-config
hostname: ${hostname}
fqdn: ${hostname}
manage_resolv_conf: true
user: ${user}
password: ${password}
ssh_authorized_keys:
  - ${ssh_authorized_keys}
chpasswd:
  expire: False
timezone: Europe/Paris
locale: fr_FR.UTF-8
keyboard:
  layout: fr
  variant: oss
package_upgrade: false
packages:
  - qemu-guest-agent
  - firewalld
  - bash-completion
runcmd:
  - sudo nmcli d disconnect eth0 && sleep 2 && sudo nmcli d connect eth0
  - sudo systemctl enable --now firewalld
output:
  init:
    output: "> /var/log/cloud-init.out"
    error: "> /var/log/cloud-init.err"
  config: "tee -a /var/log/cloud-config.log"
  final:
    - ">> /var/log/cloud-final.out"
    - "/var/log/cloud-final.err"

@JGHLab looks like you have a mismatch between the bootdisk and the disks definition. You probably need to change the bootdisk to virtio0 or change the disks definition to be scsi like below. I had the same problem with cloning, the template disk was scsi0 but TF was creating a virtio0 disk:

  disks {   
    scsi {
      scsi0 {
        disk {
          size            = 20
          cache           = "writeback"
          storage         = "local-lvm"
        }
      }
    }
  }

Thank you @jaket91-1, after matching disk with my template, now it work and no duplicate unused disk.

@JGHLab looks like you have a mismatch between the bootdisk and the disks definition. You probably need to change the bootdisk to virtio0 or change the disks definition to be scsi like below. I had the same problem with cloning, the template disk was scsi0 but TF was creating a virtio0 disk:

  disks {   
    scsi {
      scsi0 {
        disk {
          size            = 20
          cache           = "writeback"
          storage         = "local-lvm"
        }
      }
    }
  }