Terraform clone VM Behavior

ryan.tien

New Member
Jun 26, 2024
3
0
1
1734060433092.png1734060448981.png

Hi Everyone, I'm a newbie starting with Proxmox. Can anyone help answer my questions? Many thanks!:D
i have cloned 2 VM to local-lvm from a Template ( VMid: 2010 (Template-U24) by 2 ways
-this is template conf :
bios: seabios
boot: order=sata0;scsi0
cores: 2
cpu: x86-64-v2-AES
memory: 4096
meta: creation-qemu=9.0.2,ctime=179..
name: Template-U24
net0: virtio=XX:XX:XX:XX:XX:XX,bridge=vmbr0
ostype: l26
scsi0: NFS:2010/base-2010-disk-0.qcow2,discard=on,size=12G
scsihw: virtio-scsi-single
smbios1: uuid=9xxxxx....
sockets: 1
tags: template
template: 1
vmgenid: 32xxxxx...


*Second image :
I cloned VM 9004 to local-lvm using the Web UI, and everything is okay. It was very fast because I stored the VM template disk on NFS and mounted it to my Proxmox. Cloning only took 3–4 minutes for a 10GB template. if i migrate template conf to another node then I can clone VM to another node with any storage quickly !

But *First image :
- I have cloned VM 9005 using Terraform with this file: :
# Provider configuration (provider.tf)
terraform {
required_providers {
proxmox = {
source = "telmate/proxmox"
version = "3.0.1-rc4"
}
}
}

provider "proxmox" {
pm_api_url = "https://192.168.100.100:8006/api2/json"
pm_tls_insecure = true

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

# this is the full secret wrapped in quotes:
pm_api_token_secret = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxx"

}

resource "proxmox_vm_qemu" "vm-clone" {
name = "terratest-vm"
desc = "A test for using terraform and cloudinit"

target_node = "pve-100-100"

# The template name to clone this vm from
clone = "Template-U24"
full_clone = true
# Activate QEMU agent for this VM
agent = 1

os_type = "cloud-init"
cores = 2
sockets = 1
vcpus = 0
cpu = "host"
memory = 2048
scsihw = "virtio-scsi-pci"
vmid = 9005
# Setup the disk
disks {
scsi {
scsi0 {
disk {
size = 20
cache = "writeback"
storage = "local-lvm"
discard = true
#replicate = true
}
}
}
}
network {
model = "virtio"
bridge = "vmbr0"
tag = xx
}
}
Result : Terraform provisions the 9005 VM's disk to NFS first and then moves it to local-lvm storage.

Why doesn’t Terraform clone the VM directly to local-lvm ??
 
Last edited:
Why using such time consuming vm deployment ?
Prepare: Do once a template vm setup on nfs. inside vmid dir mkdir template dir and mv disk file inside, Remove disk in vm config.
Deploy: Clone the vm<id> to get new config with new vmid and new mac, maybe switch to other pve also. Reflink cp template disk on nfs filesystem into new vmid dir. Do nbd mount and change name inside and others needed. Umount the nbd. Append generated "vm image disk" line to vmid.conf. Start new vm. Full process just take seconds with simple short bash script. :)
 
Last edited:
Why using such time consuming vm deployment ?
Prepare: Do once a template vm setup on nfs. inside vmid dir mkdir template dir and mv disk file inside, Remove disk in vm config.
Deploy: Clone the vm<id> to get new config with new vmid and new mac, maybe switch to other pve also. Reflink cp template disk on nfs filesystem into new vmid dir. Do nbd mount and change name inside and others needed. Umount the nbd. Append generated "vm image disk" line to vmid.conf. Start new vm. Full process just take seconds with simple short bash script. :)
woohh, It sounds good! , thanks @walter has shared with me a new way
 
but my question has been not be explained :( . Can anyone help me explain that "why Terraform not clone the VM's disk directly to local-lvm storage" ?
 
Can anyone help me explain that "why Terraform not clone the VM's disk directly to local-lvm storage" ?
Have you tried asking at the upstream project directly? The Terraform provider is developed by a third-party, and know their provider probably best. :)
 

About

The Proxmox community has been around for many years and offers help and support for Proxmox VE, Proxmox Backup Server, and Proxmox Mail Gateway.
We think our community is one of the best thanks to people like you!

Get your subscription!

The Proxmox team works very hard to make sure you are running the best software and getting stable updates and security enhancements, as well as quick enterprise support. Tens of thousands of happy customers have a Proxmox subscription. Get yours easily in our online shop.

Buy now!