mirror of
https://github.com/bpg/terraform-provider-proxmox.git
synced 2025-07-08 14:55:02 +00:00
* feat(vm): Import Disk via API. Signed-off-by: Marco Attia <54147992+Vaneixus@users.noreply.github.com> * lint(vm): fix Linter Issues. Signed-off-by: Marco Attia <54147992+Vaneixus@users.noreply.github.com> * fix(vm): import_from update issues. Signed-off-by: Marco Attia <54147992+Vaneixus@users.noreply.github.com> * fix: store `import_from` in the state, add acc test for `import_from` Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * chore: update examples and docs Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * fix: linter Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> * chore: re-gen docs Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> --------- Signed-off-by: Marco Attia <54147992+Vaneixus@users.noreply.github.com> Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com> Co-authored-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
123 lines
3.9 KiB
Markdown
123 lines
3.9 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"
|
|
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](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"
|
|
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"
|
|
}
|
|
```
|
|
|
|
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"
|
|
# 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
|
|
}
|
|
}
|
|
```
|