0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-07-01 11:02:59 +00:00
terraform-provider-proxmox/docs/guides/cloud-image.md
Pavel Boldyrev ab09b09fbf
chore(docs): add 'stop_on_destroy' configuration to cloud image examples (#1705)
Added the 'stop_on_destroy' parameter to the Proxmox VM configurations in the cloud image documentation and example files for CentOS, Ubuntu, and Debian. This parameter should be set to true if the QEMU agent is not installed or enabled on the VM, enhancing clarity for users configuring their virtual machines.

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
2025-01-08 22:34:00 -05:00

120 lines
3.7 KiB
Markdown

---
layout: page
page_title: "Create a VM from a Cloud Image"
subcategory: Guides
description: |-
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
Proxmox does not natively support QCOW2 images, but provider can do the conversion for you.
Example of how to create a CentOS 8 VM from a "generic cloud" `qcow2` image. CentOS 8 images are available at [cloud.centos.org](https://cloud.centos.org/centos/8-stream/x86_64/images/):
```terraform
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"
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"
}
```
Ubuntu cloud images are available at [cloud-images.ubuntu.com](https://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.
```terraform
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"
file_id = 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 = "iso"
datastore_id = "local"
node_name = "pve"
url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
}
```
For [large images](https://registry.terraform.io/providers/bpg/proxmox/latest/docs/resources/virtual_environment_file#important-notes), you may want to use a dedicated temporary directory [configured](https://registry.terraform.io/providers/bpg/proxmox/latest/docs#tmp_dir) for provider via `tmp_dir` attribute, instead of system's default temporary directory. This is especially useful if you are deploying from a container with limited disk space.
## 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:
```terraform
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"
file_id = "local:iso/debian-12-genericcloud-amd64.img"
interface = "virtio0"
iothread = true
discard = "on"
size = 20
}
}
```