Skip to content

Commit 6a056cc

Browse files
committed
Fix AKS vnet names #170
The vnet name did not use the metadata_name var, and the code used to generate the name did only include the workspace. This meant it supported multiple environments in the same Azure resource group, but not multiple clusters per environment in the same resource group. With this commit, the vnet uses the metadata_name variable and the subnet will include the name of the node pool. Since changing the vnet and subnet names would require a destroy and re-create plan, existing users can keep the old names by setting `legacy_vnet_name = true`.
1 parent 30d51f7 commit 6a056cc

File tree

5 files changed

+12
-2
lines changed

5 files changed

+12
-2
lines changed

azurerm/_modules/aks/variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ variable "resource_group" {
2323
description = "Resource group to use for the cluster."
2424
}
2525

26+
variable "legacy_vnet_name" {
27+
type = bool
28+
description = "Wheter to use the legacy vnet and subnet names."
29+
default = false
30+
}
31+
2632
variable "vnet_address_space" {
2733
type = list(string)
2834
description = "Address space for the virtual network."

azurerm/_modules/aks/vnet.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
resource "azurerm_virtual_network" "current" {
33
count = var.network_plugin == "azure" ? 1 : 0
44

5-
name = "vnet-aks-${terraform.workspace}-cluster"
5+
name = var.legacy_vnet_name ? "vnet-aks-${terraform.workspace}-cluster" : var.metadata_name
66
address_space = var.vnet_address_space
77
resource_group_name = data.azurerm_resource_group.current.name
88
location = data.azurerm_resource_group.current.location
@@ -11,7 +11,7 @@ resource "azurerm_virtual_network" "current" {
1111
resource "azurerm_subnet" "current" {
1212
count = var.network_plugin == "azure" ? 1 : 0
1313

14-
name = "aks-node-subnet"
14+
name = var.legacy_vnet_name ? "aks-node-subnet" : "${var.metadata_name}-${var.default_node_pool_name}-node-pool"
1515
address_prefixes = var.subnet_address_prefixes
1616
resource_group_name = data.azurerm_resource_group.current.name
1717
virtual_network_name = azurerm_virtual_network.current[0].name

azurerm/cluster/configuration.tf

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ locals {
1919

2020
sku_tier = lookup(local.cfg, "sku_tier", "Free")
2121

22+
legacy_vnet_name = lookup(local.cfg, "legacy_vnet_name", false)
2223
vnet_address_space = split(",", lookup(local.cfg, "vnet_address_space", "10.0.0.0/8"))
2324
subnet_address_prefixes = split(",", lookup(local.cfg, "subnet_address_prefixes", "10.1.0.0/16"))
2425

azurerm/cluster/main.tf

+1
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ module "cluster" {
2929

3030
sku_tier = local.sku_tier
3131

32+
legacy_vnet_name = local.legacy_vnet_name
3233
vnet_address_space = local.vnet_address_space
3334
subnet_address_prefixes = local.subnet_address_prefixes
3435
subnet_service_endpoints = local.subnet_service_endpoints

tests/config.auto.tfvars

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ clusters = {
4343
resource_group = "terraform-kubestack-testing"
4444
name_prefix = "kbstacctest"
4545
base_domain = "infra.serverwolken.de"
46+
47+
network_plugin = "azure"
4648
}
4749

4850
# Settings for Ops-cluster

0 commit comments

Comments
 (0)