kjuulh
a3002d75a8
All checks were successful
continuous-integration/drone/push Build is passing
Signed-off-by: kjuulh <contact@kjuulh.io>
109 lines
2.4 KiB
HCL
109 lines
2.4 KiB
HCL
locals {
|
|
cloud_init_config = templatefile("${path.module}/files/cloud_init_deb12.cloud_config", {
|
|
hostname = var.name
|
|
domain = var.domain
|
|
})
|
|
}
|
|
|
|
# Create a local copy of the file, to transfer to Proxmox
|
|
resource "local_file" "cloud_init_deb12_node" {
|
|
content = local.cloud_init_config
|
|
filename = "${path.module}/files/user_data_cloud_init_deb12_${var.name}.cfg"
|
|
}
|
|
|
|
# Transfer the file to the Proxmox Host
|
|
resource "null_resource" "cloud_init_deb12_node" {
|
|
connection {
|
|
type = "ssh"
|
|
user = "root"
|
|
private_key = var.ssh_private
|
|
host = var.proxmox_ip
|
|
}
|
|
|
|
provisioner "file" {
|
|
source = local_file.cloud_init_deb12_node.source
|
|
destination = "/var/lib/vz/snippets/cloud_init_deb12_${var.name}.yml"
|
|
}
|
|
|
|
depends_on = [
|
|
local_file.cloud_init_deb12_node
|
|
]
|
|
}
|
|
|
|
|
|
# Create the VM
|
|
resource "proxmox_vm_qemu" "node" {
|
|
## Wait for the cloud-config file to exist
|
|
|
|
depends_on = [
|
|
null_resource.cloud_init_deb12_node
|
|
]
|
|
|
|
name = var.name
|
|
target_node = var.proxmox_node
|
|
|
|
# Clone from debian-cloudinit template
|
|
clone = var.cloud_init_template
|
|
os_type = "cloud-init"
|
|
|
|
# Cloud init options
|
|
cicustom = "vendor=local:snippets/cloud_init_deb12_${var.name}.yml"
|
|
ipconfig0 = "ip=${var.ip_address},gw=${var.gateway}"
|
|
|
|
cores = var.cpu
|
|
memory = var.memory
|
|
agent = 1
|
|
|
|
sshkeys = var.ssh_pub
|
|
|
|
bios = "ovmf"
|
|
|
|
ciuser = "root"
|
|
cipassword = var.user_password
|
|
|
|
# Set the boot disk paramters
|
|
bootdisk = "scsi0"
|
|
scsihw = "virtio-scsi-single"
|
|
|
|
serial {
|
|
id = 0
|
|
}
|
|
|
|
network {
|
|
id = 0
|
|
bridge = "vmbr1"
|
|
model = "virtio"
|
|
}
|
|
|
|
disks {
|
|
scsi {
|
|
scsi0 {
|
|
# We have to specify the disk from our template, else Terraform will think it's not supposed to be there
|
|
disk {
|
|
storage = "local"
|
|
# The size of the disk should be at least as big as the disk in the template. If it's smaller, the disk will be recreated
|
|
size = "10G"
|
|
}
|
|
}
|
|
}
|
|
ide {
|
|
# Some images require a cloud-init disk on the IDE controller, others on the SCSI or SATA controller
|
|
ide1 {
|
|
cloudinit {
|
|
storage = "local"
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
# Ignore changes to the network
|
|
## MAC address is generated on every apply, causing
|
|
## TF to think this needs to be rebuilt on every apply
|
|
lifecycle {
|
|
ignore_changes = [
|
|
network,
|
|
bootdisk
|
|
]
|
|
}
|
|
}
|