You've already forked kubespray-dualstack
feat: added main terraform module
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
|
||||
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
|
||||
ipv4 = each.value.ipv4
|
||||
ipv6 = each.value.ipv6
|
||||
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
|
||||
}
|
||||
Reference in New Issue
Block a user