add template vm in proxmox [ci skip]
This commit is contained in:
parent
e385407094
commit
222d3dd2b6
4 changed files with 96 additions and 38 deletions
41
modules/create-template-vm/main.tf
Normal file
41
modules/create-template-vm/main.tf
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
variable "proxmox_host" { type = string }
|
||||
variable "proxmox_user" { type = string }
|
||||
variable "cloud_image_url" { type = string }
|
||||
variable "image_path" { type = string }
|
||||
variable "template_id" {
|
||||
type = number
|
||||
default = 8000
|
||||
}
|
||||
variable "template_name" { type = string }
|
||||
|
||||
# SSH connection to Proxmox
|
||||
resource "null_resource" "create_template_remote" {
|
||||
connection {
|
||||
type = "ssh"
|
||||
user = var.proxmox_user
|
||||
host = var.proxmox_host
|
||||
private_key = file("~/.ssh/id_ed25519")
|
||||
}
|
||||
|
||||
# Commands executed *on Proxmox host*
|
||||
provisioner "remote-exec" {
|
||||
inline = [
|
||||
"set -e",
|
||||
# download the cloud image if missing
|
||||
"if [ ! -f ${var.image_path} ]; then wget -O ${var.image_path} ${var.cloud_image_url}; fi",
|
||||
# create template only if not existing
|
||||
"if ! qm status ${var.template_id} >/dev/null 2>&1; then",
|
||||
" echo 'Creating cloud-init template...';",
|
||||
" qm create ${var.template_id} --name ${var.template_name} --memory 8192 --cores 8 --net0 virtio,bridge=vmbr0;",
|
||||
" qm importdisk ${var.template_id} ${var.image_path} local-lvm;",
|
||||
" qm set ${var.template_id} --scsihw virtio-scsi-pci --scsi0 local-lvm:vm-${var.template_id}-disk-0;",
|
||||
" qm set ${var.template_id} --ide2 local-lvm:cloudinit;",
|
||||
" qm set ${var.template_id} --boot c --bootdisk scsi0;",
|
||||
" qm set ${var.template_id} --serial0 socket --vga serial0;",
|
||||
" qm template ${var.template_id};",
|
||||
"else",
|
||||
" echo 'Template ${var.template_id} already exists — skipping.';",
|
||||
"fi"
|
||||
]
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue