Packer for Proxmox & Ubuntu Stuck waiting for SSH

I’m trying to make a Proxmox Ubuntu Jammy template using Packer and I’ve been struggling to make it work.

Here’s my pkr.hcl file:

# Ubuntu Server jammy
# ---
# Packer Template to create an Ubuntu Server (jammy) on Proxmox

# Variable Definitions
variable "proxmox_api_url" {
    type = string
}

variable "proxmox_api_token_id" {
    type = string
}

variable "proxmox_api_token_secret" {
    type = string
    sensitive = true
}

# Resource Definiation for the VM Template
source "proxmox-iso" "ubuntu-server-jammy" {
 
    # Proxmox Connection Settings
    proxmox_url = "${var.proxmox_api_url}"
    username = "${var.proxmox_api_token_id}"
    token = "${var.proxmox_api_token_secret}"
    # (Optional) Skip TLS Verification
    insecure_skip_tls_verify = true
    
    # VM General Settings
    node = "pve01"
    vm_id = "30069"
    vm_name = "ubuntu-server-jammy"
    template_description = "Ubuntu Server jammy Image"

    # VM OS Settings
    iso_url = "https://releases.ubuntu.com/22.04.2/ubuntu-22.04.2-live-server-amd64.iso"
    iso_checksum = "5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931"
    iso_storage_pool = "local"
    unmount_iso = true

    # VM System Settings
    qemu_agent = true

    # VM Hard Disk Settings
    scsi_controller = "virtio-scsi-pci"

    disks {
        disk_size = "20G"
        storage_pool = "local-zfs"
        type = "virtio"
    }

    # VM CPU Settings
    cores = "2"
    
    # VM Memory Settings
    memory = "4096" 

    # VM Network Settings
    network_adapters {
        model = "virtio"
        bridge = "vmbr0"
        firewall = "false"
    } 

    # VM Cloud-Init Settings
    cloud_init = true
    cloud_init_storage_pool = "local-zfs"

    # PACKER Boot Commands
    boot_command = [
        "<esc><wait>",
        "e<wait>",
        "<down><down><down><end>",
        "<bs><bs><bs><bs><wait>",
        "autoinstall ds=nocloud-net\\;s=http://{{ .HTTPIP }}:{{ .HTTPPort }}/ ---<wait>",
        "<f10><wait>"
    ]
    boot = "c"
    boot_wait = "5s"

    # PACKER Autoinstall Settings
    http_directory = "http" 
    # (Optional) Bind IP Address and Port
    # http_bind_address = "0.0.0.0"
    # http_port_min = 8802
    # http_port_max = 8802

    ssh_username = "root"
    ssh_private_key_file = "~/.ssh/id_rsa"
    
    ssh_timeout = "20m"
}

# Build Definition to create the VM Template
build {
    name = "ubuntu-server-jammy"
    sources = ["source.proxmox-iso.ubuntu-server-jammy"]

    # Provisioning the VM Template for Cloud-Init Integration in Proxmox #1
    provisioner "shell" {
        inline = [
            "while [ ! -f /var/lib/cloud/instance/boot-finished ]; do echo 'Waiting for cloud-init...'; sleep 1; done",
            "sudo rm /etc/ssh/ssh_host_*",
            "sudo truncate -s 0 /etc/machine-id",
            "sudo apt -y autoremove --purge",
            "sudo apt -y clean",
            "sudo apt -y autoclean",
            "sudo cloud-init clean",
            "sudo rm -f /etc/cloud/cloud.cfg.d/subiquity-disable-cloudinit-networking.cfg",
            "sudo rm -f /etc/netplan/00-installer-config.yaml",
            "sudo sync"
        ]
    }

    # Provisioning the VM Template for Cloud-Init Integration in Proxmox #2
    provisioner "file" {
        source = "files/99-pve.cfg"
        destination = "/tmp/99-pve.cfg"
    }

    # Provisioning the VM Template for Cloud-Init Integration in Proxmox #3
    provisioner "shell" {
        inline = [ "sudo cp /tmp/99-pve.cfg /etc/cloud/cloud.cfg.d/99-pve.cfg" ]
    }

    # Add additional provisioning scripts here
    # ...
}

And I also have a user-data file under http folder :

#cloud-config
autoinstall:
  version: 1
  locale: en_US
  keyboard:
    layout: fr
  ssh:
    install-server: true
    allow-pw: true
    disable_root: true
    ssh_quiet_keygen: true
    allow_public_ssh_keys: true
  packages:
    - qemu-guest-agent
    - sudo
  storage:
    layout:
      name: direct
    swap:
      size: 0
  user-data:
    package_upgrade: false
    timezone: Europe/Paris
    users:
      - name: root
        groups: [adm, sudo]
        lock-passwd: false
        sudo: ALL=(ALL) NOPASSWD:ALL
        shell: /bin/bash
        ssh_authorized_keys:
          - ssh-rsa ...

The public ssh key provided in ssh_authorized_keys is one that has been generated using the private key in the file specified in ssh_private_key_file.

After few minutes on launching the build, the client side gets stuck in this step:

ares@ares:~/dev/devops/homelab/packer/ubuntu_server_jammy_yt$ packer build -var-file=./credentials.pkr.hcl ubuntu-server-jammy.pkr.hcl 
ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: output will be in this color.

==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Retrieving ISO
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Trying https://releases.ubuntu.com/22.04.2/ubuntu-22.04.2-live-server-amd64.iso
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Trying https://releases.ubuntu.com/22.04.2/ubuntu-22.04.2-live-server-amd64.iso?checksum=sha256%3A5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: https://releases.ubuntu.com/22.04.2/ubuntu-22.04.2-live-server-amd64.iso?checksum=sha256%3A5e38b55d57d94ff029719342357325ed3bda38fa80054f9330dc789cd2d43931 => /home/ares/.cache/packer/d6c27ed78f385b7455c218ba93bf575d7bb4c89e.iso
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Creating VM
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Starting VM
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Starting HTTP server on port 8813
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Waiting 5s for boot
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Typing the boot command
==> ubuntu-server-jammy.proxmox-iso.ubuntu-server-jammy: Waiting for SSH to become available...

The Proxmox Template Console is stuck in this part:

Does anyone have any idea of what I’m doing wrong ?

EDIT:
I’ve added authorized-keys in user-data file under ssh section and got the SSH part working.
I’m having another error now :

2024/02/18 20:52:45 packer-plugin-proxmox_v1.1.7_x5.0_linux_amd64 plugin: 2024/02/18 20:52:45 [DEBUG] Opening new ssh session
2024/02/18 20:52:45 packer-plugin-proxmox_v1.1.7_x5.0_linux_amd64 plugin: 2024/02/18 20:52:45 [DEBUG] Starting remote scp process:  scp -vt /tmp
2024/02/18 20:52:45 packer-plugin-proxmox_v1.1.7_x5.0_linux_amd64 plugin: 2024/02/18 20:52:45 [DEBUG] Started SCP session, beginning transfers...
2024/02/18 20:52:45 packer-plugin-proxmox_v1.1.7_x5.0_linux_amd64 plugin: 2024/02/18 20:52:45 [DEBUG] Copying input data into temporary file so we can read the length
2024/02/18 20:52:45 packer-plugin-proxmox_v1.1.7_x5.0_linux_amd64 plugin: 2024/02/18 20:52:45 [DEBUG] scp: Uploading script_7508.sh: perms=C0644 size=410
2024/02/18 20:52:45 packer-provisioner-shell plugin: Retryable error: Error uploading script: lease login as the user "NONE" rather than the user "root".