mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-08-22 11:28:33 +00:00
3.4 KiB
3.4 KiB
layout | page_title | subcategory | description |
---|---|---|---|
page | Create a VM from a Cloud Image | Guides | This guide explains how to create a VM from a cloud image. |
Create a VM from a Cloud Image
Download a public cloud image from URL
Example of how to create a CentOS 8 VM from a "generic cloud" qcow2
image. CentOS 8 images are available at cloud.centos.org:
resource "proxmox_virtual_environment_vm" "centos_vm" {
name = "test-centos"
node_name = "pve"
# should be true if qemu agent is not installed / enabled on the VM
stop_on_destroy = true
initialization {
user_account {
# do not use this in production, configure your own ssh key instead!
username = "user"
password = "password"
}
}
disk {
datastore_id = "local-lvm"
import_from = 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 = "import"
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"
}
Ubuntu cloud images are available at cloud-images.ubuntu.com. Ubuntu cloud images are in qcow2
format as well, but stored with .img
extension, so they can be directly uploaded to Proxmox without renaming.
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
name = "test-ubuntu"
node_name = "pve"
# should be true if qemu agent is not installed / enabled on the VM
stop_on_destroy = true
initialization {
user_account {
# do not use this in production, configure your own ssh key instead!
username = "user"
password = "password"
}
}
disk {
datastore_id = "local-lvm"
import_from = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
interface = "virtio0"
iothread = true
discard = "on"
size = 20
}
}
resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
content_type = "import"
datastore_id = "local"
node_name = "pve"
url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
# need to rename the file to *.qcow2 to indicate the actual file format for import
file_name = "jammy-server-cloudimg-amd64.qcow2"
}
Create a VM from an existing image on Proxmox
If you already have a cloud image on Proxmox, you can use it to create a VM:
resource "proxmox_virtual_environment_vm" "debian_vm" {
name = "test-debian"
node_name = "pve"
# should be true if qemu agent is not installed / enabled on the VM
stop_on_destroy = true
initialization {
user_account {
# do not use this in production, configure your own ssh key instead!
username = "user"
password = "password"
}
}
disk {
datastore_id = "local-lvm"
# qcow2 image downloaded from https://cloud.debian.org/images/cloud/bookworm/latest/ and renamed to *.img
# the image is not of import type, so provider will use SSH client to import it
file_id = "local:iso/debian-12-genericcloud-amd64.img"
interface = "virtio0"
iothread = true
discard = "on"
size = 20
}
}