Skip to content
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

Creating clone always results in unused disk #1067

Open
DennisSerafin opened this issue Aug 1, 2024 · 10 comments
Open

Creating clone always results in unused disk #1067

DennisSerafin opened this issue Aug 1, 2024 · 10 comments

Comments

@DennisSerafin
Copy link

Issue: Disk in Unused State After Cloning Template with Terraform

Description

When cloning a Windows template using the PVE GUI, everything works as expected and Windows boots perfectly. However, when cloning the template using Terraform with the telmate/proxmox provider, the boot disk is in an unused state, as shown in the attached screenshot.

Terraform Configuration

modules/vm/main.tf

terraform {
  required_providers {
    proxmox = {
      source = "telmate/proxmox"
    }
  }
}

resource "proxmox_vm_qemu" "vm" {
  name        = var.name
  target_node = var.target_node

  clone      = var.template_name
  full_clone = true

  os_type    = "cloud-init"
  ciuser     = "user"
  cipassword = "password"

  cores   = var.cores
  sockets = 1
  memory  = var.memory

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

#     disks {
#       scsi {
#         scsi1 {
#           disk {
#             storage = "cephvm"
#             size    = var.disk_size
#           }
#         }
#       }

#    }

  ipconfig0  = "ip=${var.ip_address}/24,gw=${var.gateway}"
  nameserver = join(" ", var.dns_servers)
}

Steps to Reproduce

  1. Use the provided Terraform configuration to clone a Windows template.
  2. Observe that the disk is in an unused state.

Expected Behavior

The cloned VM should boot up with the disk properly attached, as it does when cloned via the PVE GUI.

Actual Behavior

The disk is in an unused state, preventing the VM from booting properly.

Additional Context

  • Proxmox Version: 8.2.2
  • Terraform Version: v1.7.2-dev
  • Provider Version: v3.0.1-rc3

I have cloudbase-init installed on the Windows template.

Workaround

If there is a workaround or manual steps that need to be performed to resolve the issue, please describe them here.

Screenshot_20240801_140336

@Tinyblargon
Copy link
Collaborator

@DennisSerafin the disk has to be configured in Terraform, as Terraform will make the cloned vm as configured. Any properties that are not configured in the TF file but are carried over from the original VM are bugs or lack of implementation.

@DennisSerafin
Copy link
Author

Thanks for the quick answer. Is there no chance I can use the cloned disk from my template as a boot device for the cloned VMs when I clone via Terraform?

@Tinyblargon
Copy link
Collaborator

@DennisSerafin if you configure a disk in the same slot as the disk from the original vm, Terraform will see that the disk is an intended part of the configuration and keep it. Do keep in mind that the configured dis has to be at least as big as the original, or else it will be recreated.

@DennisSerafin
Copy link
Author

@Tinyblargon, thanks for the info. The problem is, when I create the new disk the same size as the cloned disk, Terraform replaces the old one, making the disk appear empty. The disk size from the template is 80GB, and here is what I added in modules/vm/main.tf:

  disks {
    scsi {
      scsi0 {
        disk {
          storage = "cephvm"
          size    = "80G"
        }
      }
    }
  }

  boot     = "cdn"
  bootdisk = "scsi0"

Now, the unused disk is gone, but it can't boot the OS that was installed in the template.

@Tinyblargon
Copy link
Collaborator

@DennisSerafin currently we only detach the disk, so if it isn't detached it should still be tge same drive. I think boot="scsi0" and bootdisk should not be specified.

@DennisSerafin
Copy link
Author

@Tinyblargon I removed bootdisk = "scsi0" but unfortunately he didn't boot the disk. The vm didn´t seems to know that it has a bootable device like shown in the next screenshot:

Screenshot_20240802_074701

so i tried to boot manually from disk, but this didn't work eithter:

Screenshot_20240802_074845

i used the same .yml with the disk part. So I must be overlooking something, any ideas?
just to take out mistakes: My Template has 80GB and there is Windows Server 2022 installed with Cloudbase-Init. When i Manually clone the Template, everything works as intended.
thanks for the help

@thiraphi
Copy link

Hello @DennisSerafin, I got the same error. And after a huge amount of time searching I got the solution from this https://github.com/Telmate/terraform-provider-proxmox/issues/770#issuecomment-1552567416
. By adding `scsihw = "virtio-scsi-pci" in 'Resource' section

FYI: this is my main.tf

    resource "proxmox_vm_qemu" "cloudinit-test" {
        name = "terraform-test-vm"
        desc = "A test for using terraform and cloudinit"
        target_node = "localhost"
   
        clone = "VM 9000"
    
        agent = 1
    
        os_type = "cloud-init"
        cores = 2
        sockets = 1
        vcpus = 0
        cpu = "host"
        memory = 2048
    
        scsihw  = "virtio-scsi-pci"
    
        hotplug  = "network,disk,usb"
    
        disks {
            scsi {
                scsi0 {
                    disk {
                      storage = "local-lvm"
                      size = 12
                    }
                }
            }
            ide {
                ide3 {
                    cloudinit {
                      storage = "local-lvm"
                    }
                }
            }
        }

        bootdisk = "scsi0"

    }

@DennisSerafin
Copy link
Author

DennisSerafin commented Aug 14, 2024

@thiraphi thanks for your answer, unfortunately this din´t work. I think it din´t clone the Disk, it create a new Disk instead.

main.tf

resource "proxmox_vm_qemu" "vm" {
  name        = "TEST"
  target_node = "rhbhstp004"

  clone      = "Template"
  //full_clone = true

  agent = 1

  os_type    = "cloud-init"
  ciuser     = "User"
  cipassword = "Password"

  cores   = "4"
  sockets = 1
  memory  = "8096"

  scsihw = "virtio-scsi-pci"
  hotplug  = "network,disk,usb"

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

  disks {
    scsi {
      scsi0 {
        disk {
          storage = "cephvm"
          size    = "80G"
        }
      }
    }

    ide {
      ide3 {
        cloudinit {
          storage = "cephvm"
        }
      }
    }
  }

  bootdisk = "scsi0"

}

it dint´t boot from disk. It seems like the Disk is empty.

the Template:
image

and when i manually clone the Template, everything works as expected

@thiraphi
Copy link

@DennisSerafin
Can you try to create a new template by following the steps in this doc? I think the issue is related to the VirtIO SCSI controller. After I added --scsihw virtio-scsi-pci when creating the template, it worked.

@mammalmaster
Copy link

@thiraphi thanks for your answer, unfortunately this din´t work. I think it din´t clone the Disk, it create a new Disk instead.

main.tf

resource "proxmox_vm_qemu" "vm" {
  name        = "TEST"
  target_node = "rhbhstp004"

  clone      = "Template"
  //full_clone = true

  agent = 1

  os_type    = "cloud-init"
  ciuser     = "User"
  cipassword = "Password"

  cores   = "4"
  sockets = 1
  memory  = "8096"

  scsihw = "virtio-scsi-pci"
  hotplug  = "network,disk,usb"

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

  disks {
    scsi {
      scsi0 {
        disk {
          storage = "cephvm"
          size    = "80G"
        }
      }
    }

    ide {
      ide3 {
        cloudinit {
          storage = "cephvm"
        }
      }
    }
  }

  bootdisk = "scsi0"

}

it dint´t boot from disk. It seems like the Disk is empty.

the Template: image

and when i manually clone the Template, everything works as expected

This worked for me on a linux install. I was trying a bunch of things but the disk was always unmounted, thank you for this!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants