HCL
resource "proxmox_virtual_environment_vm" "ubuntu_vm" {
count = 2
name = "terraform-provider-proxmox-ubuntu-vm"
description = "Managed by Terraform"
tags = ["terraform", "ubuntu"]
node_name = "pve1"
vm_id = 4321 + count.index
agent {
# read 'Qemu guest agent' section, change to true only when ready
enabled = false
}
startup {
order = "3"
up_delay = "60"
down_delay = "60"
}
disk {
datastore_id = "local-lvm"
interface = "scsi0"
file_format = "raw"
}
initialization {
ip_config {
ipv4 {
address = "dhcp"
}
}
user_account {
keys = [trimspace(tls_private_key.ubuntu_vm_key.public_key_openssh)]
password = random_password.ubuntu_vm_password.result
username = "ubuntu"
}
}
network_device {
bridge = "vmbr0"
}
cdrom {
enabled = true
file_id = "local:iso/debian-12-ps.iso"
}
operating_system {
type = "l26"
}
tpm_state {
version = "v2.0"
}
serial_device {}
}
resource "random_password" "ubuntu_vm_password" {
length = 16
override_special = "_%@"
special = true
}
resource "tls_private_key" "ubuntu_vm_key" {
algorithm = "RSA"
rsa_bits = 2048
}
output "ubuntu_vm_password" {
value = random_password.ubuntu_vm_password.result
sensitive = true
}
output "ubuntu_vm_private_key" {
value = tls_private_key.ubuntu_vm_key.private_key_pem
sensitive = true
}
output "ubuntu_vm_public_key" {
value = tls_private_key.ubuntu_vm_key.public_key_openssh
}