You've already forked kubespray-dualstack
71 lines
1.8 KiB
Terraform
71 lines
1.8 KiB
Terraform
resource "libvirt_network" "default" {
|
|
name = "${var.naming_prefix}default"
|
|
mode = "nat"
|
|
addresses = local.cidrs
|
|
mtu = var.mtu
|
|
autostart = true
|
|
|
|
dns {
|
|
local_only = false
|
|
|
|
forwarders {
|
|
address = "1.1.1.1"
|
|
}
|
|
}
|
|
}
|
|
|
|
resource "libvirt_volume" "base" {
|
|
name = "${var.naming_prefix}ubuntu_noble"
|
|
source = local.image_source
|
|
}
|
|
|
|
resource "libvirt_volume" "control_plane_image" {
|
|
name = "${var.naming_prefix}control_plane_image"
|
|
base_volume_id = libvirt_volume.base.id
|
|
size = 10737418240
|
|
}
|
|
|
|
resource "libvirt_volume" "worker_images" {
|
|
for_each = { for ip in var.worker_ipv4s : "worker_${replace(ip, "\\.", "-")}" => ip }
|
|
name = "${var.naming_prefix}${each.key}_image"
|
|
base_volume_id = libvirt_volume.base.id
|
|
size = 10737418240
|
|
}
|
|
|
|
data "template_file" "user_data" {
|
|
for_each = local.user_templates
|
|
|
|
template = file("${path.module}/configs/cloud-init/${each.value}")
|
|
vars = {
|
|
hosts_file = base64encode(file("${path.module}/configs/hosts"))
|
|
ssh_public_key = file("../.ssh/id_rsa.pub")
|
|
}
|
|
}
|
|
|
|
data "template_file" "network_config" {
|
|
for_each = local.user_templates
|
|
|
|
template = file("${path.module}/configs/cloud-init/network.yaml.tpl")
|
|
vars = {
|
|
ipv4_address = local.node_addrs[each.key].ipv4
|
|
ipv4_prefix = local.ipv4_prefix
|
|
ipv4_gateway = local.ipv4_gateway
|
|
ipv6_address = local.node_addrs[each.key].ipv6
|
|
ipv6_prefix = local.ipv6_prefix
|
|
ipv6_gateway = local.ipv6_gateway
|
|
}
|
|
}
|
|
|
|
module "nodes" {
|
|
source = "./modules/instance"
|
|
for_each = local.nodes
|
|
|
|
name = each.key
|
|
network_id = libvirt_network.default.id
|
|
volume_base_id = each.value.image
|
|
user_data = each.value.user_data
|
|
network_config = each.value.network_config
|
|
vcpu = var.cpu_per_node
|
|
memory = var.mem_per_node
|
|
}
|