2024-08-20 19:03:23 +00:00
|
|
|
locals {
|
|
|
|
nodes_with_names = {
|
|
|
|
for k, v in var.nodes : k => merge(v, {
|
|
|
|
id = 700 + index(keys(var.nodes), k)
|
2024-08-21 21:00:23 +00:00
|
|
|
name = "${v.name}.ingress.tjo.cloud"
|
2024-08-20 19:03:23 +00:00
|
|
|
hash = sha1(v.name)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
nodes = {
|
|
|
|
for k, v in local.nodes_with_names : k => merge(v, {
|
|
|
|
mac_address = "AA:BB:07:00:${format("%v:%v", substr(v.hash, 0, 2), substr(v.hash, 2, 2))}"
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ipv6_addresses = {
|
|
|
|
for key, node in local.nodes : key => {
|
|
|
|
for k, v in proxmox_virtual_environment_vm.nodes[key].ipv6_addresses :
|
|
|
|
proxmox_virtual_environment_vm.nodes[key].network_interface_names[k] => v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
nodes_with_address = {
|
|
|
|
for k, v in local.nodes :
|
|
|
|
k => merge(v, {
|
|
|
|
ipv4 = local.ipv4_addresses[k]["eth0"][0]
|
|
|
|
ipv6 = local.ipv6_addresses[k]["eth0"][0]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "proxmox_virtual_environment_file" "ingress" {
|
|
|
|
content_type = "iso"
|
|
|
|
datastore_id = var.common_storage
|
|
|
|
node_name = values(var.nodes)[0].host
|
|
|
|
|
|
|
|
source_file {
|
|
|
|
path = var.image_path
|
|
|
|
file_name = "ingress-tjo-cloud.img"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "proxmox_virtual_environment_file" "cloudinit" {
|
|
|
|
for_each = local.nodes
|
|
|
|
|
|
|
|
node_name = each.value.host
|
|
|
|
content_type = "snippets"
|
|
|
|
datastore_id = var.common_storage
|
|
|
|
|
|
|
|
source_raw {
|
|
|
|
data = <<-EOF
|
|
|
|
|
|
|
|
EOF
|
2024-08-21 21:00:23 +00:00
|
|
|
file_name = "${each.value.name}.cloudinit.yaml"
|
2024-08-20 19:03:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
resource "proxmox_virtual_environment_vm" "nodes" {
|
|
|
|
for_each = local.nodes
|
|
|
|
|
|
|
|
vm_id = each.value.id
|
|
|
|
name = each.value.name
|
|
|
|
node_name = each.value.host
|
|
|
|
|
|
|
|
description = "Node ${each.value.name} for ingress.tjo.cloud."
|
|
|
|
tags = concat(
|
|
|
|
["tjo-space"],
|
|
|
|
[each.value.name]
|
|
|
|
)
|
|
|
|
|
|
|
|
stop_on_destroy = true
|
|
|
|
timeout_start_vm = 60
|
|
|
|
timeout_stop_vm = 60
|
|
|
|
timeout_shutdown_vm = 60
|
|
|
|
timeout_reboot = 60
|
|
|
|
timeout_create = 120
|
|
|
|
|
|
|
|
cpu {
|
|
|
|
cores = each.value.cores
|
|
|
|
type = "host"
|
|
|
|
}
|
|
|
|
memory {
|
|
|
|
dedicated = each.value.memory
|
|
|
|
}
|
|
|
|
|
2024-08-21 21:00:23 +00:00
|
|
|
bios = "ovmf"
|
|
|
|
|
2024-08-20 19:03:23 +00:00
|
|
|
operating_system {
|
|
|
|
type = "l26"
|
|
|
|
}
|
|
|
|
|
|
|
|
agent {
|
|
|
|
enabled = true
|
|
|
|
timeout = "1m"
|
|
|
|
}
|
|
|
|
|
|
|
|
network_device {
|
|
|
|
bridge = each.value.bridge
|
|
|
|
mac_address = each.value.mac_address
|
|
|
|
}
|
|
|
|
|
|
|
|
scsi_hardware = "virtio-scsi-single"
|
|
|
|
disk {
|
2024-08-21 21:00:23 +00:00
|
|
|
file_id = proxmox_virtual_environment_file.ingress.id
|
|
|
|
file_format = "qcow2"
|
2024-08-20 19:03:23 +00:00
|
|
|
interface = "virtio0"
|
|
|
|
datastore_id = each.value.storage
|
|
|
|
size = each.value.boot_size
|
|
|
|
backup = true
|
|
|
|
cache = "none"
|
|
|
|
iothread = true
|
|
|
|
}
|
|
|
|
|
|
|
|
initialization {
|
|
|
|
datastore_id = each.value.storage
|
|
|
|
meta_data_file_id = proxmox_virtual_environment_file.cloudinit[each.key].id
|
|
|
|
}
|
|
|
|
}
|