Skip to content

Commit a653e61

Browse files
HiranAdikariclaude
andcommitted
Support auto route mode for non-VyOS VLAN networks in tenant-space
When vlan_id is set without vyos_endpoint, use route_mode=auto so the upstream router (DigiOps / physical switch) handles DHCP and routing. The manual route_mode with deterministic 10.0.0.0/8 subnetting is now gated on vyos_endpoint being set. - Add use_vyos local; gate tenant_subnet/tenant_gateway computation on it - harvester_network route_mode, route_cidr, route_gateway are conditional - Relax vlan_id validation from >= 1000 to valid 802.1Q range (1–4094) - Update subnet_cidr/gateway_ip output descriptions (VyOS-only) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 33eeddc commit a653e61

4 files changed

Lines changed: 21 additions & 13 deletions

File tree

modules/management/tenant-space/main.tf

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ locals {
99
create_net_ns = var.create_network_namespace || var.vlan_id != null
1010
network_namespace = local.create_net_ns ? "${var.project_name}-net" : null
1111

12-
tenant_subnet = var.vlan_id != null ? cidrsubnet("10.0.0.0/8", 15, var.vlan_id - 1000) : null
13-
tenant_gateway = var.vlan_id != null ? cidrhost(local.tenant_subnet, 1) : null
12+
# VyOS path: compute a deterministic /23 subnet from 10.0.0.0/8 using the VLAN
13+
# index. Only relevant when vyos_endpoint is set; auto-routed environments
14+
# (physical switch / DigiOps-issued VLANs) do not need explicit subnets.
15+
use_vyos = var.vlan_id != null && var.vyos_endpoint != null
16+
tenant_subnet = local.use_vyos ? cidrsubnet("10.0.0.0/8", 15, var.vlan_id - 1000) : null
17+
tenant_gateway = local.use_vyos ? cidrhost(local.tenant_subnet, 1) : null
1418
}
1519

1620
resource "rancher2_project" "this" {
@@ -101,9 +105,13 @@ resource "harvester_network" "tenant" {
101105
namespace = rancher2_namespace.network[0].name
102106
vlan_id = var.vlan_id
103107
cluster_network_name = var.cluster_network_name
104-
route_mode = "manual"
105-
route_cidr = local.tenant_subnet
106-
route_gateway = local.tenant_gateway
108+
109+
# VyOS path: manual routing with a deterministic /23 from 10.0.0.0/8.
110+
# DigiOps / physical-switch path: auto routing — the upstream router
111+
# advertises the gateway; no explicit CIDR or gateway needed here.
112+
route_mode = local.use_vyos ? "manual" : "auto"
113+
route_cidr = local.tenant_subnet
114+
route_gateway = local.tenant_gateway
107115

108116
# When VyOS is configured, wait for the vif/DHCP to be provisioned before
109117
# the network is visible to tenant VMs. count=0 module depends_on is a no-op.

modules/management/tenant-space/outputs.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ output "network_name" {
2929
}
3030

3131
output "subnet_cidr" {
32-
value = var.vlan_id != null ? local.tenant_subnet : null
33-
description = "Tenant /23 subnet CIDR (e.g. 10.0.0.0/23). Null when vlan_id is not set."
32+
value = local.tenant_subnet
33+
description = "Tenant /23 subnet CIDR (e.g. 10.0.0.0/23). Non-null only when vlan_id and vyos_endpoint are both set."
3434
}
3535

3636
output "gateway_ip" {
37-
value = var.vlan_id != null ? local.tenant_gateway : null
38-
description = "VyOS gateway IP for this tenant. Null when vlan_id is not set."
37+
value = local.tenant_gateway
38+
description = "VyOS gateway IP for this tenant (first host in subnet_cidr). Non-null only when vlan_id and vyos_endpoint are both set."
3939
}

modules/management/tenant-space/variables.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ variable "create_network_namespace" {
105105

106106
variable "vlan_id" {
107107
type = number
108-
description = "VLAN ID for this tenant's network (>= 1000). When set, creates the network namespace (if not already), a harvester_network, and optionally VyOS config when vyos_endpoint is also provided. When null, no network or VyOS resources are created."
108+
description = "VLAN ID for this tenant's network (>= 1000). When set, always creates the network namespace and a harvester_network. Routing mode depends on vyos_endpoint: if set, route_mode=manual with a deterministic /23 from 10.0.0.0/8 plus full VyOS vif/DHCP/NAT config; if null, route_mode=auto (upstream router / DigiOps-issued VLAN handles routing). When vlan_id is null, no network resources are created."
109109
default = null
110110
validation {
111-
condition = var.vlan_id == null || var.vlan_id >= 1000
112-
error_message = "vlan_id must be >= 1000."
111+
condition = var.vlan_id == null || (var.vlan_id >= 1 && var.vlan_id <= 4094)
112+
error_message = "vlan_id must be a valid 802.1Q VLAN ID (1–4094)."
113113
}
114114
}
115115

modules/management/tenant-space/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ terraform {
99
source = "harvester/harvester"
1010
version = "~> 1.7"
1111
}
12-
}
12+
}
1313
}

0 commit comments

Comments
 (0)