Add adaptive router VM/interface scaling and local delivery integrity tests
Terraform now provisions router_count IaaS Router VMs (default 2, no longer hardcoded to router1/router2), each with 1 public + private_interface_count isolated private interfaces (no shared LAN or VRRP between routers). Both counts scale via Terraform variables and TF_VAR_* environment variables. The post-install script became a Terraform template that matches interfaces to their expected subnet by CIDR instead of a fragile "first private IP" heuristic. Added an offline pytest suite (terraform/tests/) that checks the delivery's internal consistency and runs real terraform init/validate against the actual vkcs provider schema via a project-local filesystem mirror (provider binary fetched from its GitHub releases, bypassing the region-blocked HashiCorp registry) - no cloud credentials or API calls involved. terraform/versions.tf now declares the previously-missing required_providers block. Ansible (inventory.ini, base/frr_router/keepalived roles) still assumes the old 2-router/2-NIC/VRRP topology and is not yet adapted - documented as a follow-up, not addressed here. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011hXR2ftXZZhJ4Y3XuSoR8r
This commit is contained in:
1 parent
e711faca42
commit
5979a9a58b
20 files changed
+1181
-139
No files matched your search
+70
-75
@@ -9,7 +9,7 @@ data "vkcs_images_image" "ubuntu24" {
|
||||
|
||||
data "vkcs_networking_network" "extnet" {
|
||||
name = "internet"
|
||||
sdn = "sprut"
|
||||
sdn = "sprut"
|
||||
}
|
||||
|
||||
# LAN Network
|
||||
@@ -20,12 +20,12 @@ resource "vkcs_networking_network" "lan_net" {
|
||||
}
|
||||
|
||||
resource "vkcs_networking_subnet" "lan_subnet" {
|
||||
network_id = vkcs_networking_network.lan_net.id
|
||||
name = "router-lan-subnet"
|
||||
cidr = "10.200.10.0/24"
|
||||
gateway_ip = "10.200.10.1"
|
||||
network_id = vkcs_networking_network.lan_net.id
|
||||
name = "router-lan-subnet"
|
||||
cidr = "10.200.10.0/24"
|
||||
gateway_ip = "10.200.10.1"
|
||||
dns_nameservers = ["8.8.8.8", "1.1.1.1"]
|
||||
sdn = "sprut"
|
||||
sdn = "sprut"
|
||||
|
||||
allocation_pool {
|
||||
start = "10.200.10.100"
|
||||
@@ -42,7 +42,7 @@ resource "vkcs_networking_secgroup" "router_sg" {
|
||||
resource "vkcs_networking_secgroup" "private_sg" {
|
||||
name = "private-sg"
|
||||
sdn = "sprut"
|
||||
}
|
||||
}
|
||||
|
||||
# Private SG rules
|
||||
resource "vkcs_networking_secgroup_rule" "from_rfc_net192_in" {
|
||||
@@ -105,40 +105,62 @@ resource "vkcs_networking_secgroup_rule" "router_ipsec_nat_t" {
|
||||
sdn = "sprut"
|
||||
}
|
||||
|
||||
# Router LAN Ports
|
||||
resource "vkcs_networking_port" "lan_port1" {
|
||||
name = "router1-lan-port"
|
||||
network_id = vkcs_networking_network.lan_net.id
|
||||
admin_state_up = true
|
||||
port_security_enabled = false
|
||||
full_security_groups_control = true
|
||||
security_group_ids = []
|
||||
sdn = "sprut"
|
||||
fixed_ip {
|
||||
subnet_id = vkcs_networking_subnet.lan_subnet.id
|
||||
ip_address = "10.200.10.254"
|
||||
# Per-router private interface subnets: each router gets `private_roles` isolated
|
||||
# micro-subnets (no shared LAN, no VRRP), carved out of private_supernet.
|
||||
locals {
|
||||
private_roles = [for i in range(var.private_interface_count) : "priv${i + 1}"]
|
||||
|
||||
router_private_subnets = {
|
||||
for pair in setproduct(range(var.router_count), local.private_roles) :
|
||||
"router${pair[0] + 1}-${pair[1]}" => {
|
||||
router_index = pair[0]
|
||||
role = pair[1]
|
||||
cidr = cidrsubnet(
|
||||
var.private_supernet,
|
||||
var.private_subnet_prefix_length - tonumber(split("/", var.private_supernet)[1]),
|
||||
pair[0] * length(local.private_roles) + index(local.private_roles, pair[1])
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "vkcs_networking_port" "lan_port2" {
|
||||
name = "router2-lan-port"
|
||||
network_id = vkcs_networking_network.lan_net.id
|
||||
admin_state_up = true
|
||||
port_security_enabled = false
|
||||
resource "vkcs_networking_network" "router_priv_net" {
|
||||
for_each = local.router_private_subnets
|
||||
name = "router-${each.key}-net"
|
||||
sdn = "sprut"
|
||||
admin_state_up = true
|
||||
}
|
||||
|
||||
resource "vkcs_networking_subnet" "router_priv_subnet" {
|
||||
for_each = local.router_private_subnets
|
||||
network_id = vkcs_networking_network.router_priv_net[each.key].id
|
||||
name = "router-${each.key}-subnet"
|
||||
cidr = each.value.cidr
|
||||
gateway_ip = cidrhost(each.value.cidr, 1)
|
||||
sdn = "sprut"
|
||||
}
|
||||
|
||||
resource "vkcs_networking_port" "router_priv_port" {
|
||||
for_each = local.router_private_subnets
|
||||
name = "router-${each.key}-port"
|
||||
network_id = vkcs_networking_network.router_priv_net[each.key].id
|
||||
admin_state_up = true
|
||||
port_security_enabled = false
|
||||
full_security_groups_control = true
|
||||
security_group_ids = []
|
||||
sdn = "sprut"
|
||||
security_group_ids = []
|
||||
sdn = "sprut"
|
||||
fixed_ip {
|
||||
subnet_id = vkcs_networking_subnet.lan_subnet.id
|
||||
ip_address = "10.200.10.253"
|
||||
subnet_id = vkcs_networking_subnet.router_priv_subnet[each.key].id
|
||||
ip_address = cidrhost(each.value.cidr, 2)
|
||||
}
|
||||
}
|
||||
|
||||
resource "vkcs_compute_instance" "router1" {
|
||||
name = "router1"
|
||||
resource "vkcs_compute_instance" "router" {
|
||||
count = var.router_count
|
||||
name = "router${count.index + 1}"
|
||||
image_id = data.vkcs_images_image.ubuntu24.id
|
||||
flavor_name = "STD3-4-4"
|
||||
availability_zone = "ME1"
|
||||
availability_zone = element(var.router_availability_zones, count.index % length(var.router_availability_zones))
|
||||
key_pair = var.ssh_key_name
|
||||
|
||||
security_group_ids = [
|
||||
@@ -147,56 +169,29 @@ resource "vkcs_compute_instance" "router1" {
|
||||
]
|
||||
|
||||
config_drive = true
|
||||
|
||||
# Configure persistent networking using script
|
||||
user_data = file("${path.module}/scripts/network-init.sh")
|
||||
|
||||
# Configure persistent networking using script: WAN via heuristic public-IP
|
||||
# detection, private interfaces matched by their expected CIDR.
|
||||
user_data = templatefile("${path.module}/scripts/network-init.sh.tpl", {
|
||||
private_interfaces = [
|
||||
for role in local.private_roles : {
|
||||
name = "eth${index(local.private_roles, role) + 1}"
|
||||
cidr = local.router_private_subnets["router${count.index + 1}-${role}"].cidr
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
# WAN: dynamically created port
|
||||
network {
|
||||
uuid = data.vkcs_networking_network.extnet.id
|
||||
}
|
||||
|
||||
# LAN: pre-created port
|
||||
network {
|
||||
port = vkcs_networking_port.lan_port1.id
|
||||
}
|
||||
|
||||
block_device {
|
||||
uuid = data.vkcs_images_image.ubuntu24.id
|
||||
source_type = "image"
|
||||
volume_size = 20
|
||||
boot_index = 0
|
||||
destination_type = "volume"
|
||||
volume_type = "ceph-ssd"
|
||||
delete_on_termination = true
|
||||
}
|
||||
}
|
||||
|
||||
resource "vkcs_compute_instance" "router2" {
|
||||
name = "router2"
|
||||
image_id = data.vkcs_images_image.ubuntu24.id
|
||||
flavor_name = "STD3-4-4"
|
||||
availability_zone = "ME1"
|
||||
key_pair = var.ssh_key_name
|
||||
|
||||
security_group_ids = [
|
||||
vkcs_networking_secgroup.router_sg.id,
|
||||
"d479b4d7-55b3-4ff1-bf8d-24d826a38f11"
|
||||
]
|
||||
|
||||
config_drive = true
|
||||
|
||||
# Configure persistent networking using script
|
||||
user_data = file("${path.module}/scripts/network-init.sh")
|
||||
|
||||
# WAN: dynamically created port
|
||||
network {
|
||||
uuid = data.vkcs_networking_network.extnet.id
|
||||
}
|
||||
|
||||
# LAN: pre-created port
|
||||
network {
|
||||
port = vkcs_networking_port.lan_port2.id
|
||||
# Private: one pre-created isolated port per role
|
||||
dynamic "network" {
|
||||
for_each = local.private_roles
|
||||
content {
|
||||
port = vkcs_networking_port.router_priv_port["router${count.index + 1}-${network.value}"].id
|
||||
}
|
||||
}
|
||||
|
||||
block_device {
|
||||
|
||||
Reference in new issue
Block a user