Skip to content

Unable to create template VM with imported disk on a file-based datastore #1959

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
jeka opened this issue May 11, 2025 · 6 comments
Open
Labels
🐛 bug Something isn't working

Comments

@jeka
Copy link

jeka commented May 11, 2025

Describe the bug
I am unable to create a working VM template when using an image as a base for the disk (disk.file_id)

To Reproduce
Steps to reproduce the behavior:

  1. Using the following Terraform template:
locals {
  storage = "data"
  vmname  = "test-template"
}

resource "proxmox_virtual_environment_vm" "fedora_template" {
  name      = local.vmname
  node_name = "proxmox"
  vm_id     = 9000

  template = true
  started  = false

  disk {
    datastore_id = local.storage
    file_id      = "data:iso/fedora-42-cloud.qcow2.img"
    interface    = "scsi0"
    file_format  = "qcow2"
  }
}

Creates a broken VM template with configuration:

$ qm config 9000

acpi: 1
agent: enabled=0,fstrim_cloned_disks=0,type=virtio
balloon: 0
bios: seabios
boot: order=scsi0;net0
cores: 1
cpu: cputype=qemu64
cpuunits: 1024
keyboard: en-us
memory: 512
meta: creation-qemu=9.2.0,ctime=1746953902
name: test-template
numa: 0
onboot: 1
ostype: other
protection: 0
scsi0: data:9000/vm-9000-disk-0.qcow2,aio=io_uring,backup=1,cache=none,discard=ignore,iothread=0,replicate=1,size=8G,ssd=0
scsihw: virtio-scsi-pci
smbios1: uuid=dbd407d5-80ac-481b-b263-5720896b8365
sockets: 1
tablet: 1
template: 1
vmgenid: 5f6db2ab-7aa0-4e90-bbf8-93d68b02f50

Trying to create a linked clone from this template returns an error:

Linked clone feature is not supported for 'data:9000/vm-9000-disk-0.qcow2' (scsi0) (500)
  1. If I don't use disk.file_id, the template is created OK (albeit not useful)
  2. If I create a VM (just set template = false) and convert it to a template afterwards (via WEB UI) the result is a working template VM.

The base file is created with tofu also:

locals {
  storage = "data"
} 

resource "proxmox_virtual_environment_download_file" "fedora_cloud_image" {
  content_type = "iso"
  datastore_id = local.storage
  node_name    = "proxmox"
  file_name    = "fedora-42-cloud.qcow2.img"

  url = "https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
}

Datastore_id data is directory based storage (EXT4)

Additional context

  • Single-node Proxmox
  • Proxmox version: 8.4.1
  • Provider version: 0.77.1
  • Terraform/OpenTofu version: OpenTofu v1.9.1
  • OS (where you run Terraform/OpenTofu from): KDE neon 6.3 (Ubuntu 24.04)
@bpg
Copy link
Owner

bpg commented May 13, 2025

Similar to #998

@jeka
Copy link
Author

jeka commented May 14, 2025

Yes, it is similar (if not the same). But that issue is closed as not planned.
The question now is: Is there a plan for fixing this?

@bpg
Copy link
Owner

bpg commented May 14, 2025

Yes, it is similar (if not the same). But that issue is closed as not planned. The question now is: Is there a plan for fixing this?

The older issue was auto-closed dues to lack of activity, then somebody found a workable solution, Then the conversation in the issue thread veered away from the initial problem anyway, so I don't see the point to reopen that.

I don't have immediate plans to fix this issue as it seems to be related to a very specific use case, and I'm not using linked clones in my lab.

@jeka
Copy link
Author

jeka commented May 14, 2025

Fair enough, it's your code after all.
Although I disagree that it's a very specific use case. Using linked clones is a very common case IMO.

@jeka
Copy link
Author

jeka commented May 17, 2025

Uh, I messed up my comment somehow ...

Anyway, this issue is not about failing to create clones, linked or not.
It's about the failure to create templates from imported disk images.

@bpg
Copy link
Owner

bpg commented May 21, 2025

Datastore_id data is directory based storage (EXT4)

I’d say the issue is still quite specific and likely related to the type of datastore you're using. For a block-level datastore the source image can be used as-is, but I guess for a file-level datastore it needs to be converted, which UI does, but provider doesn't.

I’d say the issue is still quite specific and likely related to the type of datastore you're using. For file-level datastores, the source image probably needs to be converted, which PVE UI does, but provider currently doesn't.

This config works without issues in my lab on LVM datastore:

resource "proxmox_virtual_environment_vm" "fedora_template" {
  name      = "fedora-template"
  node_name = "pve"

  template        = true
  stop_on_destroy = true

  initialization {
    user_account {
      username = "user"
      password = "password"
    }
  }

  disk {
    datastore_id = "local-lvm"
    file_id      = proxmox_virtual_environment_download_file.fedora_cloud_image.id
    interface    = "virtio0"
    iothread     = true
    discard      = "on"
    size         = 20
  }
}

resource "proxmox_virtual_environment_download_file" "fedora_cloud_image" {
  content_type = "iso"
  datastore_id = "local"
  node_name    = "pve"
  url          = "https://download.fedoraproject.org/pub/fedora/linux/releases/42/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-42-1.1.x86_64.qcow2"
  file_name    = "fedora.img"
}

resource "proxmox_virtual_environment_vm" "fedora_clone" {
  node_name       = "pve"
  name            = "fedora-clone"
  started         = true
  stop_on_destroy = true

  clone {
    vm_id = proxmox_virtual_environment_vm.fedora_template.vm_id
  }

  disk {
    datastore_id = "tank"
    interface    = "virtio0"
    iothread     = true
    discard      = "on"
    size         = 20
  }

  initialization {
    dns {
      servers = ["172.16.0.15", "172.16.0.16"]
      domain = "example.com"
    }
    ip_config {
      ipv4 {
        address = "192.168.3.233/24"
        gateway = "192.168.3.1"
      }
    }

    user_account {
      username = "user2"
      password = "password2"
    }
  }
}

Though I see some segfaults in the console, they probably not related

Image

Also tried the same with centos:

resource "proxmox_virtual_environment_vm" "centos_template" {
  name      = "centos-template"
  node_name = "pve"

  template        = true
  stop_on_destroy = true

  initialization {
    user_account {
      username = "user"
      password = "password"
    }
  }

  disk {
    datastore_id = "local-lvm"
    file_id      = proxmox_virtual_environment_download_file.centos_cloud_image.id
    interface    = "virtio0"
    iothread     = true
    discard      = "on"
    size         = 20
  }
}

resource "proxmox_virtual_environment_download_file" "centos_cloud_image" {
  content_type = "iso"
  datastore_id = "local"
  node_name    = "pve"
  url          = "https://cloud.centos.org/centos/8-stream/x86_64/images/CentOS-Stream-GenericCloud-8-latest.x86_64.qcow2"
  file_name    = "centos8.img"
}

resource "proxmox_virtual_environment_vm" "centos_clone" {
  node_name       = "pve"
  name            = "centos-clone"
  started         = true
  stop_on_destroy = true

  clone {
    vm_id = proxmox_virtual_environment_vm.centos_template.vm_id
  }

  disk {
    datastore_id = "tank"
    interface    = "virtio0"
    iothread     = true
    discard      = "on"
    size         = 20
  }

  initialization {
    dns {
      servers = ["172.16.0.15", "172.16.0.16"]
      domain = "example.com"
    }
    ip_config {
      ipv4 {
        address = "192.168.3.233/24"
        gateway = "192.168.3.1"
      }
    }

    user_account {
      username = "user2"
      password = "password2"
    }
  }
}

This worked perfectly.

Image

@bpg bpg changed the title Unable to create template VM with imported disk Unable to create template VM with imported disk on a file-based datastore May 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐛 bug Something isn't working
Projects
Status: 📥 Inbox
Development

No branches or pull requests

2 participants