ProxMox and Terraform "VM '<id>' not found"

edymol

New Member
Nov 20, 2024
6
1
3
Hello.

I am new to ProxMox and perhaps this has been already asked, although I have not seen a similar question yet.

I am trying to use Terraform to provision my infrastructure in PoxMox but I keep on getting this error.
Code:
[CODE=bash][CODE]proxmox_vm_qemu.ubuntu_vm: Creating...
╷
│ Error: vm '8000' not found
│
│   with proxmox_vm_qemu.ubuntu_vm,
│   on main.tf line 16, in resource "proxmox_vm_qemu" "ubuntu_vm":
│   16: resource "proxmox_vm_qemu" "ubuntu_vm" {
[/CODE][/CODE]

I have created different users and roles to try to make it work but it has not worked
Screenshot 2024-11-20 at 11.41.55 AM.png

Here is the main.tf that I am using for this test

root@proxmox:~/devops/terraform# cat main.tf
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = ">= 2.9.11"
}
}
}

provider "proxmox" {
pm_api_url = var.pm_api_url
pm_user = var.pm_user
pm_password = var.pm_password
pm_debug = var.pm_debug

resource "proxmox_vm_qemu" "ubuntu_vm" {
name = "ubuntu_vm" # Name of the new VM
target_node = "proxmox" # Node where the VM will be created
clone = 8000 # Template ID for cloning the VM

# VM Resources
cpu = 2
memory = 2048
sockets = 1

# Disk Configuration
disk {
storage = "vm-pool" # Ensure this matches the storage pool for the template
size = "32G"
type = "scsi"
iothread = 1
}

# Network Configuration
network {
model = "virtio"
bridge = "vmbr0"
}

# Cloud-init Configuration
os_type = "cloud-init"
ssh_user = "devops-user"
sshkeys = file("~/.ssh/id_rsa.pub")
ipconfig0 = "ip=192.168.100.50/24,gw=192.168.100.1"
}

Here are the different templates I have created but all give back the same error.
Screenshot 2024-11-20 at 11.43.51 AM.png
I am using this versions

Bash:
root@proxmox:~/devops/terraform# pveversion
pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve)


I also have used API token that works when used in CLI

Bash:
curl -k -X GET "https://192.168.100.27:8006/api2/json/version" -H "Authorization: PVEAPIToken=terraform@pve!terraform:285ecb71-6c"

Has anyone had the same issue recently and how was this solved?

Thank you for your help. Screenshot 2024-11-20 at 11.41.55 AM.pngScreenshot 2024-11-20 at 11.43.51 AM.png
 
Last edited:
Hi @edymol , welcome to the forum.

The terraform code is not maintained by PVE personnel, you would have to reach out to the creator of TF code for a definitive answer.
In the meantime, you can dig into the code yourself to see what API call is being generated, that may tell you what is wrong.
If there is a way to add some "print" statements, that could help as well.

Try to do the same thing via direct "curl", using your authentication token.

Good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
 
Hi @edymol , welcome to the forum.

The terraform code is not maintained by PVE personnel, you would have to reach out to the creator of TF code for a definitive answer.
In the meantime, you can dig into the code yourself to see what API call is being generated, that may tell you what is wrong.
If there is a way to add some "print" statements, that could help as well.

Try to do the same thing via direct "curl", using your authentication token.

Good luck



Blockbridge : Ultra low latency all-NVME shared storage for Proxmox - https://www.blockbridge.com/proxmox
Hello bbgeek13,

Thanks for your response.

I managed to fix the issue of the "not found" but now I have other issues at hand.

I fixed the issue using a different provider version and syntax.

Now I face the issue that the template VMs are not finding the bootable disk and this is the error.

proxmox_vm_qemu.ubuntu_vm[0]: Still creating... [4m20s elapsed]╷│ Error: error updating VM: 500 invalid bootorder: device 'scsi0' does not exist', error status: {"data":null} (params: map[agent:0 bios:seabios boot:order=scsi0 cores:2 cpu:host delete:ide2,scsi0 hotplug:network,disk,usb ipconfig0:ip=192.168.0.50/24 kvm:true memory:2048 name:debian-vm-1 net0:virtio=B2:6E:90:D1:32:43,bridge=vmbr0 numa:false onboot:true protection:false scsihw:virtio-scsi-pci sockets:1 tablet:true vmid:105])││ with proxmox_vm_qemu.ubuntu_vm[0],│ on main.tf line 19, in resource "proxmox_vm_qemu" "ubuntu_vm":│ 19: resource "proxmox_vm_qemu" "ubuntu_vm" {│╵

I will continue troubleshooting this and hopefully have a solid fix so I can run IoC without issues.

Thanks again
 
Hello.

I am new to ProxMox and perhaps this has been already asked, although I have not seen a similar question yet.

I am trying to use Terraform to provision my infrastructure in PoxMox but I keep on getting this error.
Code:
[CODE=bash][CODE]proxmox_vm_qemu.ubuntu_vm: Creating...
╷
│ Error: vm '8000' not found
│
│   with proxmox_vm_qemu.ubuntu_vm,
│   on main.tf line 16, in resource "proxmox_vm_qemu" "ubuntu_vm":
│   16: resource "proxmox_vm_qemu" "ubuntu_vm" {
[/CODE][/CODE]

I have created different users and roles to try to make it work but it has not worked
View attachment 77982

Here is the main.tf that I am using for this test

root@proxmox:~/devops/terraform# cat main.tf
terraform {
required_providers {
proxmox = {
source = "Telmate/proxmox"
version = ">= 2.9.11"
}
}
}

provider "proxmox" {
pm_api_url = var.pm_api_url
pm_user = var.pm_user
pm_password = var.pm_password
pm_debug = var.pm_debug

resource "proxmox_vm_qemu" "ubuntu_vm" {
name = "ubuntu_vm" # Name of the new VM
target_node = "proxmox" # Node where the VM will be created
clone = 8000 # Template ID for cloning the VM

# VM Resources
cpu = 2
memory = 2048
sockets = 1

# Disk Configuration
disk {
storage = "vm-pool" # Ensure this matches the storage pool for the template
size = "32G"
type = "scsi"
iothread = 1
}

# Network Configuration
network {
model = "virtio"
bridge = "vmbr0"
}

# Cloud-init Configuration
os_type = "cloud-init"
ssh_user = "devops-user"
sshkeys = file("~/.ssh/id_rsa.pub")
ipconfig0 = "ip=192.168.100.50/24,gw=192.168.100.1"
}

Here are the different templates I have created but all give back the same error.
View attachment 77983
I am using this versions

Bash:
root@proxmox:~/devops/terraform# pveversion
pve-manager/8.2.2/9355359cd7afbae4 (running kernel: 6.8.4-2-pve)


I also have used API token that works when used in CLI

Bash:
curl -k -X GET "https://192.168.100.27:8006/api2/json/version" -H "Authorization: PVEAPIToken=terraform@pve!terraform:285ecb71-6c"

Has anyone had the same issue recently and how was this solved?

Thank you for your help. View attachment 77982View attachment 77983
Hi, I have encountered the same issue, with pve 8.2.2 and terraform 2.9.11,
Have you found the cause and a solution?
 
Hi, I have encountered the same issue, with pve 8.2.2 and terraform 2.9.11,
Have you found the cause and a solution?
Yes. I fixed the issues now terraform is provisioning correctly. I will try to put the solution on GitHub and make a video for it.
 
  • Like
Reactions: waltar
Will try to get it done ASAP
I will not have time to make the video but this is the portion of the Terraform I fixed to make it work with proxmox. if you have a specific error, please share. Thanks.

Code:
resource "proxmox_vm_qemu" "cloudinit-test" {
  name        = var.vm_name
  desc        = var.vm_description
  target_node = var.target_node
  clone       = var.template_vm
  agent       = var.enable_agent

  os_type  = var.os_type
  cores    = var.cpu_cores
  sockets  = var.cpu_sockets
  vcpus    = var.virtual_cpus
  cpu      = var.cpu_model
  memory   = var.memory_size
  scsihw   = var.scsihw
  cicustom = var.cicustom_file

# Below is how I managed to set up the block to make the disk readable for provision

  disks {
    ide {
      ide2 {
        cloudinit {
          storage = var.cloudinit_storage
        }
      }
    }
    scsi {
      scsi0 {
        disk {
          size      = var.disk_size
          cache     = var.disk_cache
          storage   = var.disk_storage
          replicate = var.disk_replicate
        }
      }
    }
  }

  network {
    model  = var.network_model
    bridge = var.network_bridge
  }

  boot       = var.boot_order
  ipconfig0  = var.ip_configuration
  ciuser     = var.cloudinit_user
  cipassword = var.cloudinit_password
  sshkeys = var.ssh_public_key

# Below is the providers and the version I used to make it work with the syntax provided above. 
terraform {
  required_providers {
    proxmox = {
      source  = "telmate/proxmox"
      version = "3.0.1-rc4"
    }
  }
}

provider "proxmox" {
  pm_api_url          = var.pm_api_url
  pm_api_token_id     = var.pm_api_token_id
  pm_api_token_secret = var.pm_api_token_secret
}
    id   = var.serial_id
    type = var.serial_type
  }

}

Let me know how it goes.
 
Thx , it works now, I think there are 2 major sources of errors:
1. token authorization
2. proxmox_vm_qemu key names varies among different provider versions
I will not have time to make the video but this is the portion of the Terraform I fixed to make it work with proxmox. if you have a specific error, please share. Thanks.

Code:
resource "proxmox_vm_qemu" "cloudinit-test" {
  name        = var.vm_name
  desc        = var.vm_description
  target_node = var.target_node
  clone       = var.template_vm
  agent       = var.enable_agent

  os_type  = var.os_type
  cores    = var.cpu_cores
  sockets  = var.cpu_sockets
  vcpus    = var.virtual_cpus
  cpu      = var.cpu_model
  memory   = var.memory_size
  scsihw   = var.scsihw
  cicustom = var.cicustom_file

# Below is how I managed to set up the block to make the disk readable for provision

  disks {
    ide {
      ide2 {
        cloudinit {
          storage = var.cloudinit_storage
        }
      }
    }
    scsi {
      scsi0 {
        disk {
          size      = var.disk_size
          cache     = var.disk_cache
          storage   = var.disk_storage
          replicate = var.disk_replicate
        }
      }
    }
  }

  network {
    model  = var.network_model
    bridge = var.network_bridge
  }

  boot       = var.boot_order
  ipconfig0  = var.ip_configuration
  ciuser     = var.cloudinit_user
  cipassword = var.cloudinit_password
  sshkeys = var.ssh_public_key

# Below is the providers and the version I used to make it work with the syntax provided above.
terraform {
  required_providers {
    proxmox = {
      source  = "telmate/proxmox"
      version = "3.0.1-rc4"
    }
  }
}

provider "proxmox" {
  pm_api_url          = var.pm_api_url
  pm_api_token_id     = var.pm_api_token_id
  pm_api_token_secret = var.pm_api_token_secret
}
    id   = var.serial_id
    type = var.serial_type
  }

}

Let me know how it goes.