116 lines
2.6 KiB
HCL
116 lines
2.6 KiB
HCL
locals {
|
|
domain = "network.tjo.cloud"
|
|
|
|
nodes = {
|
|
for k, v in var.nodes : k => merge(v, {
|
|
domain = local.domain
|
|
id = 700 + index(keys(var.nodes), k)
|
|
hash = sha1(v.host)
|
|
|
|
wan_mac_address = v.mac_address != null ? v.mac_address : "AA:BB:00:00:${format("%v:%v", substr(sha1(v.host), 0, 2), substr(sha1(v.host), 2, 2))}"
|
|
private_mac_address = "AA:BB:00:11:${format("%v:%v", substr(sha1(v.host), 0, 2), substr(sha1(v.host), 2, 2))}"
|
|
})
|
|
}
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_network_linux_bridge" "vmbr0" {
|
|
for_each = local.nodes
|
|
|
|
node_name = each.value.host
|
|
name = "vmbr0"
|
|
comment = "Main interface bridge for VMs."
|
|
|
|
address = each.value.address
|
|
gateway = each.value.gateway
|
|
ports = each.value.bridge_ports
|
|
}
|
|
|
|
|
|
resource "proxmox_virtual_environment_network_linux_bridge" "vmbr1" {
|
|
for_each = local.nodes
|
|
|
|
node_name = each.value.host
|
|
name = "vmbr1"
|
|
comment = "Private network for VMs."
|
|
}
|
|
|
|
resource "proxmox_virtual_environment_file" "iso" {
|
|
for_each = local.nodes
|
|
|
|
content_type = "iso"
|
|
datastore_id = each.value.iso_storage
|
|
node_name = each.value.host
|
|
|
|
source_file {
|
|
path = "${path.module}/../iso/OPNsense-24.7-dvd-amd64.iso"
|
|
}
|
|
}
|
|
|
|
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 = "OPNsense instance for ${each.value.host}."
|
|
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 = false
|
|
}
|
|
|
|
network_device {
|
|
bridge = "vmbr0"
|
|
mac_address = each.value.wan_mac_address
|
|
}
|
|
|
|
network_device {
|
|
bridge = proxmox_virtual_environment_network_linux_bridge.vmbr1[each.key].name
|
|
mac_address = each.value.private_mac_address
|
|
}
|
|
|
|
scsi_hardware = "virtio-scsi-single"
|
|
|
|
dynamic "cdrom" {
|
|
for_each = each.value.iso_enabled ? [1] : []
|
|
content {
|
|
file_id = proxmox_virtual_environment_file.iso[each.key].id
|
|
interface = "ide0"
|
|
}
|
|
}
|
|
|
|
disk {
|
|
interface = "scsi0"
|
|
datastore_id = each.value.boot_storage
|
|
size = 16
|
|
backup = true
|
|
cache = "none"
|
|
iothread = true
|
|
file_format = "raw"
|
|
}
|
|
}
|