137 lines
3.2 KiB
HCL
137 lines
3.2 KiB
HCL
locals {
|
|
domain = "ingress.tjo.cloud"
|
|
|
|
nodes = {
|
|
for k, v in var.nodes : k => merge(v, {
|
|
id = 800 + index(keys(var.nodes), k)
|
|
hash = sha1(v.host)
|
|
mac_address = "AA:BB:07:00:${format("%v:%v", substr(sha1(v.host), 0, 2), substr(sha1(v.host), 2, 2))}"
|
|
domain = local.domain
|
|
meta = {
|
|
name = v.host
|
|
domain = local.domain
|
|
service_account = {
|
|
username = authentik_user.service_account[k].username
|
|
password = authentik_token.service_account[k].key
|
|
}
|
|
}
|
|
})
|
|
}
|
|
|
|
ipv4_addresses = {
|
|
for key, node in local.nodes : key => {
|
|
for k, v in proxmox_virtual_environment_vm.nodes[key].ipv4_addresses :
|
|
proxmox_virtual_environment_vm.nodes[key].network_interface_names[k] => v
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_download_file" "ubuntu" {
|
|
for_each = local.nodes
|
|
|
|
content_type = "iso"
|
|
datastore_id = each.value.iso_storage
|
|
node_name = each.value.host
|
|
url = "https://cloud-images.ubuntu.com/noble/current/noble-server-cloudimg-amd64.img"
|
|
overwrite = false
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_file" "userdata" {
|
|
for_each = local.nodes
|
|
|
|
node_name = each.value.host
|
|
content_type = "snippets"
|
|
datastore_id = each.value.iso_storage
|
|
|
|
source_raw {
|
|
data = <<-EOF
|
|
#cloud-config
|
|
hostname: ${each.value.host}.${each.value.domain}
|
|
write_files:
|
|
- path: /etc/tjo.cloud/meta.json
|
|
encoding: base64
|
|
content: ${base64encode(jsonencode(each.value.meta))}
|
|
ssh_authorized_keys: ${jsonencode(var.ssh_keys)}
|
|
packages:
|
|
- qemu-guest-agent
|
|
power_state:
|
|
mode: reboot
|
|
EOF
|
|
file_name = "${each.value.host}.ingress.tjo.cloud.userconfig.yaml"
|
|
}
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_vm" "nodes" {
|
|
for_each = local.nodes
|
|
|
|
vm_id = each.value.id
|
|
name = "${each.value.host}.${each.value.domain}"
|
|
node_name = each.value.host
|
|
|
|
description = <<EOT
|
|
An ingress.tjo.cloud instance for ${each.value.host}.
|
|
|
|
Repo: https://code.tjo.space/tjo-cloud/ingress
|
|
EOT
|
|
|
|
tags = [each.value.domain]
|
|
|
|
stop_on_destroy = true
|
|
timeout_start_vm = 60
|
|
timeout_stop_vm = 60
|
|
timeout_shutdown_vm = 60
|
|
timeout_reboot = 60
|
|
timeout_create = 600
|
|
|
|
cpu {
|
|
cores = each.value.cores
|
|
type = "host"
|
|
}
|
|
memory {
|
|
dedicated = each.value.memory
|
|
}
|
|
|
|
bios = "ovmf"
|
|
efi_disk {
|
|
datastore_id = each.value.boot_storage
|
|
}
|
|
|
|
operating_system {
|
|
type = "l26"
|
|
}
|
|
|
|
agent {
|
|
enabled = true
|
|
}
|
|
|
|
network_device {
|
|
bridge = "vmbr1"
|
|
mac_address = each.value.mac_address
|
|
}
|
|
|
|
scsi_hardware = "virtio-scsi-single"
|
|
disk {
|
|
file_id = proxmox_virtual_environment_download_file.ubuntu[each.key].id
|
|
interface = "virtio0"
|
|
datastore_id = each.value.boot_storage
|
|
size = each.value.boot_size
|
|
backup = true
|
|
cache = "none"
|
|
iothread = true
|
|
}
|
|
|
|
initialization {
|
|
interface = "scsi0"
|
|
datastore_id = each.value.boot_storage
|
|
user_data_file_id = proxmox_virtual_environment_file.userdata[each.key].id
|
|
|
|
ip_config {
|
|
ipv4 {
|
|
address = "dhcp"
|
|
}
|
|
ipv6 {
|
|
address = "dhcp"
|
|
}
|
|
}
|
|
}
|
|
}
|