Files
Proxmox/main.tf
T
2026-11-13 10:59:09 +01:00

131 lines
3.0 KiB
Terraform

data "proxmox_virtual_environment_nodes" "nodes" {}
# data "proxmox_datastores" "datastores" {
# node_name = data.proxmox_virtual_environment_nodes.nodes.names[0]
# }
#
# output "datastores" {
# value = data.proxmox_datastores.datastores
# }
resource "proxmox_download_file" "ubuntu_cloud" {
content_type = "import"
datastore_id = var.datastore_id
node_name = var.node
url = "https://cloud-images.ubuntu.com/releases/resolute/release/ubuntu-26.04-server-cloudimg-amd64.img"
file_name = "ubuntu-26-04-server-cloudimg.qcow2"
}
resource "proxmox_virtual_environment_file" "qemu-startup" {
content_type = "snippets"
datastore_id = var.datastore_id
node_name = var.node
source_raw {
data = templatefile("${path.module}/cloud-inits/qemu.yaml.tftpl", { password = var.vm_password
username = var.vm_username })
file_name = "qemu-startup-config.yaml"
}
}
resource "proxmox_virtual_environment_vm" "ailab" {
name = "ailab"
description = "sandboxed playground for ai agents"
tags = ["ai", "ubuntu"]
node_name = var.node
keyboard_layout = "de"
bios = "ovmf"
machine = "q35"
scsi_hardware = "virtio-scsi-single"
operating_system {
type = "l26"
}
efi_disk {
datastore_id = var.datastore_id
type = "4m"
pre_enrolled_keys = false
}
disk {
datastore_id = var.datastore_id
import_from = proxmox_download_file.ubuntu_cloud.id
interface = "scsi0"
size = "64"
discard = "on"
iothread = true
ssd = true
}
initialization {
datastore_id = var.datastore_id
user_data_file_id = proxmox_virtual_environment_file.qemu-startup.id
ip_config {
ipv4 {
address = "dhcp"
}
}
}
agent {
enabled = true
}
serial_device {}
cpu {
cores = 2
type = "host"
}
memory {
dedicated = 8192
floating = 8192
}
network_device {
bridge = "vmbr2"
firewall = true
}
}
output "test" {
value = flatten([for ipv4 in proxmox_virtual_environment_vm.ailab.ipv4_addresses : ipv4 if !contains(ipv4, "127.0.0.1")])[0]
}
data "ansible_inventory" "ailab" {
group {
name = "sanboxes"
host {
name = flatten([for ipv4 in proxmox_virtual_environment_vm.ailab.ipv4_addresses : ipv4 if !contains(ipv4, "127.0.0.1")])[0]
ansible_user = var.vm_username
ansible_password = var.vm_password
}
}
}
action "ansible_playbook_run" "update_ailab" {
config {
playbooks = ["${path.module}/ansible/playbook.yaml"]
inventories = [data.ansible_inventory.ailab.json]
}
}
resource "terraform_data" "playbook_trigger" {
input = {
vm_id = proxmox_virtual_environment_vm.ailab.id
playbook_hash = filemd5("${path.module}/ansible/playbook.yaml")
}
lifecycle {
action_trigger {
events = [after_create, after_update]
actions = [action.ansible_playbook_run.update_ailab]
}
}
depends_on = [proxmox_virtual_environment_vm.ailab]
}