97 lines
2.1 KiB
HCL
97 lines
2.1 KiB
HCL
locals {
|
|
nodes = {
|
|
nereus-node1 = {
|
|
address = var.node_addresses["nereus-node1"]
|
|
role = "server"
|
|
}
|
|
nereus-node2 = {
|
|
address = var.node_addresses["nereus-node2"]
|
|
role = "agent"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "libvirt_network" "nereus" {
|
|
name = "nereus"
|
|
mode = "nat"
|
|
domain = "nereus.test"
|
|
addresses = [var.network_cidr]
|
|
|
|
dhcp {
|
|
enabled = true
|
|
}
|
|
|
|
dns {
|
|
enabled = true
|
|
}
|
|
}
|
|
|
|
resource "libvirt_volume" "fedora" {
|
|
name = "nereus-fedora-44-base.qcow2"
|
|
pool = "default"
|
|
source = var.fedora_image_url
|
|
format = "qcow2"
|
|
}
|
|
|
|
resource "libvirt_volume" "node" {
|
|
for_each = local.nodes
|
|
name = "${each.key}.qcow2"
|
|
pool = "default"
|
|
base_volume_id = libvirt_volume.fedora.id
|
|
size = 30 * 1024 * 1024 * 1024
|
|
}
|
|
|
|
resource "libvirt_cloudinit_disk" "node" {
|
|
for_each = local.nodes
|
|
name = "${each.key}-cloud-init.iso"
|
|
pool = "default"
|
|
user_data = templatefile("${path.module}/cloud-init.yaml.tftpl", {
|
|
hostname = each.key
|
|
ssh_public_key = var.ssh_public_key
|
|
})
|
|
}
|
|
|
|
resource "libvirt_domain" "node" {
|
|
for_each = local.nodes
|
|
|
|
name = each.key
|
|
memory = 3072
|
|
vcpu = 2
|
|
autostart = true
|
|
cloudinit = libvirt_cloudinit_disk.node[each.key].id
|
|
|
|
disk {
|
|
volume_id = libvirt_volume.node[each.key].id
|
|
}
|
|
|
|
network_interface {
|
|
network_id = libvirt_network.nereus.id
|
|
hostname = each.key
|
|
addresses = [each.value.address]
|
|
wait_for_lease = true
|
|
}
|
|
|
|
console {
|
|
type = "pty"
|
|
target_type = "serial"
|
|
target_port = "0"
|
|
}
|
|
|
|
graphics {
|
|
type = "spice"
|
|
listen_type = "address"
|
|
autoport = true
|
|
}
|
|
}
|
|
|
|
resource "local_sensitive_file" "inventory" {
|
|
filename = "${path.module}/inventory.yml"
|
|
file_permission = "0600"
|
|
content = templatefile("${path.module}/inventory.yml.tftpl", {
|
|
private_key_file = var.ssh_private_key_file
|
|
operator_cidrs = var.operator_cidrs
|
|
node_cidr = var.network_cidr
|
|
server_address = local.nodes["nereus-node1"].address
|
|
agent_address = local.nodes["nereus-node2"].address
|
|
})
|
|
}
|