0
0
mirror of https://github.com/bpg/terraform-provider-proxmox.git synced 2025-08-22 11:28:33 +00:00

chore(docs): cleanup and update clone-vm example (#2094)

Signed-off-by: Pavel Boldyrev <627562+bpg@users.noreply.github.com>
This commit is contained in:
Pavel Boldyrev 2025-08-10 20:15:00 -04:00 committed by GitHub
parent 6e8712490b
commit c7cd61a2d3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 35 additions and 19 deletions

View File

@ -3,21 +3,21 @@ layout: page
page_title: "Clone a VM" page_title: "Clone a VM"
subcategory: Guides subcategory: Guides
description: |- description: |-
This guide explains how to create a VM template and then clone it to another VM. This guide explains how to create a VM template and clone it to a new VM.
--- ---
# Clone a VM # Clone a VM
## Create a VM template ## Create a VM template
VM templates in Proxmox provide an efficient way to create multiple identical VMs. Templates act as a base image that can be cloned to create new VMs, ensuring consistency and reducing the time needed to provision new instances. When a VM is created as a template, it is read-only and can't be started, but can be cloned multiple times to create new VMs. VM templates in Proxmox provide an efficient way to create multiple identical VMs. Templates act as a base image that can be cloned to create new VMs, ensuring consistency and reducing the time needed to provision new instances. When a VM is created as a template, it is read-only and cannot be started, but can be cloned multiple times to create new VMs.
You can create a template directly in Proxmox by setting the `template` attribute to `true` when creating the VM resource: You can create a template with Terraform by setting the `template` attribute to `true` when creating the VM resource:
```terraform ```terraform
resource "proxmox_virtual_environment_vm" "ubuntu_template" { resource "proxmox_virtual_environment_vm" "ubuntu_template" {
name = "ubuntu-template" name = "ubuntu-template"
node_name = "pve" node_name = var.virtual_environment_node_name
template = true template = true
started = false started = false
@ -35,12 +35,12 @@ resource "proxmox_virtual_environment_vm" "ubuntu_template" {
} }
efi_disk { efi_disk {
datastore_id = "local" datastore_id = var.datastore_id
type = "4m" type = "4m"
} }
disk { disk {
datastore_id = "local-lvm" datastore_id = var.datastore_id
file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
interface = "virtio0" interface = "virtio0"
iothread = true iothread = true
@ -67,18 +67,18 @@ resource "proxmox_virtual_environment_vm" "ubuntu_template" {
resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" { resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
content_type = "iso" content_type = "iso"
datastore_id = "local" datastore_id = "local"
node_name = "pve" node_name = var.virtual_environment_node_name
url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
} }
``` ```
Once you have a template, you can clone it to create new VMs. The cloned VMs will inherit all the configuration from the template but can be customized further as needed. Once you have a template, you can clone it to create new VMs. The cloned VMs will inherit all configuration from the template but can be customized further as needed.
```terraform ```terraform
resource "proxmox_virtual_environment_vm" "ubuntu_clone" { resource "proxmox_virtual_environment_vm" "ubuntu_clone" {
name = "ubuntu-clone" name = "ubuntu-clone"
node_name = "pve" node_name = var.virtual_environment_node_name
clone { clone {
vm_id = proxmox_virtual_environment_vm.ubuntu_template.id vm_id = proxmox_virtual_environment_vm.ubuntu_template.id
@ -113,3 +113,5 @@ output "vm_ipv4_address" {
value = proxmox_virtual_environment_vm.ubuntu_clone.ipv4_addresses[1][0] value = proxmox_virtual_environment_vm.ubuntu_clone.ipv4_addresses[1][0]
} }
``` ```
Full example is available in the [examples/guides/clone-vm](https://github.com/bpg/terraform-provider-proxmox/tree/main/examples/guides/clone-vm) directory.

View File

@ -1,6 +1,6 @@
resource "proxmox_virtual_environment_vm" "ubuntu_clone" { resource "proxmox_virtual_environment_vm" "ubuntu_clone" {
name = "ubuntu-clone" name = "ubuntu-clone"
node_name = "pve" node_name = var.virtual_environment_node_name
clone { clone {
vm_id = proxmox_virtual_environment_vm.ubuntu_template.id vm_id = proxmox_virtual_environment_vm.ubuntu_template.id

View File

@ -5,7 +5,7 @@ data "local_file" "ssh_public_key" {
resource "proxmox_virtual_environment_file" "user_data_cloud_config" { resource "proxmox_virtual_environment_file" "user_data_cloud_config" {
content_type = "snippets" content_type = "snippets"
datastore_id = "local" datastore_id = "local"
node_name = "pve" node_name = var.virtual_environment_node_name
source_raw { source_raw {
data = <<-EOF data = <<-EOF

View File

@ -1,6 +1,6 @@
resource "proxmox_virtual_environment_vm" "ubuntu_template" { resource "proxmox_virtual_environment_vm" "ubuntu_template" {
name = "ubuntu-template" name = "ubuntu-template"
node_name = "pve" node_name = var.virtual_environment_node_name
template = true template = true
started = false started = false
@ -18,12 +18,12 @@ resource "proxmox_virtual_environment_vm" "ubuntu_template" {
} }
efi_disk { efi_disk {
datastore_id = "local" datastore_id = var.datastore_id
type = "4m" type = "4m"
} }
disk { disk {
datastore_id = "local-lvm" datastore_id = var.datastore_id
file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id file_id = proxmox_virtual_environment_download_file.ubuntu_cloud_image.id
interface = "virtio0" interface = "virtio0"
iothread = true iothread = true
@ -50,7 +50,7 @@ resource "proxmox_virtual_environment_vm" "ubuntu_template" {
resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" { resource "proxmox_virtual_environment_download_file" "ubuntu_cloud_image" {
content_type = "iso" content_type = "iso"
datastore_id = "local" datastore_id = "local"
node_name = "pve" node_name = var.virtual_environment_node_name
url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img" url = "https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img"
} }

View File

@ -8,3 +8,15 @@ variable "virtual_environment_token" {
description = "The token for the Proxmox Virtual Environment API" description = "The token for the Proxmox Virtual Environment API"
sensitive = true sensitive = true
} }
variable "virtual_environment_node_name" {
type = string
description = "The node name for the Proxmox Virtual Environment API"
default = "pve"
}
variable "datastore_id" {
type = string
description = "Datastore for VM disks"
default = "local-lvm"
}

View File

@ -3,19 +3,21 @@ layout: page
page_title: "Clone a VM" page_title: "Clone a VM"
subcategory: Guides subcategory: Guides
description: |- description: |-
This guide explains how to create a VM template and then clone it to another VM. This guide explains how to create a VM template and clone it to a new VM.
--- ---
# Clone a VM # Clone a VM
## Create a VM template ## Create a VM template
VM templates in Proxmox provide an efficient way to create multiple identical VMs. Templates act as a base image that can be cloned to create new VMs, ensuring consistency and reducing the time needed to provision new instances. When a VM is created as a template, it is read-only and can't be started, but can be cloned multiple times to create new VMs. VM templates in Proxmox provide an efficient way to create multiple identical VMs. Templates act as a base image that can be cloned to create new VMs, ensuring consistency and reducing the time needed to provision new instances. When a VM is created as a template, it is read-only and cannot be started, but can be cloned multiple times to create new VMs.
You can create a template directly in Proxmox by setting the `template` attribute to `true` when creating the VM resource: You can create a template with Terraform by setting the `template` attribute to `true` when creating the VM resource:
{{ codefile "terraform" "examples/guides/clone-vm/template.tf" }} {{ codefile "terraform" "examples/guides/clone-vm/template.tf" }}
Once you have a template, you can clone it to create new VMs. The cloned VMs will inherit all the configuration from the template but can be customized further as needed. Once you have a template, you can clone it to create new VMs. The cloned VMs will inherit all configuration from the template but can be customized further as needed.
{{ codefile "terraform" "examples/guides/clone-vm/clone.tf" }} {{ codefile "terraform" "examples/guides/clone-vm/clone.tf" }}
Full example is available in the [examples/guides/clone-vm](https://github.com/bpg/terraform-provider-proxmox/tree/main/examples/guides/clone-vm) directory.