2024-07-06 02:21:50 +02:00
|
|
|
locals {
|
|
|
|
# Subdivide the virtual network into subnets
|
|
|
|
# - controllers use netnum 0
|
|
|
|
# - workers use netnum 1
|
|
|
|
controller_subnets = {
|
|
|
|
ipv4 = [for i, cidr in var.network_cidr.ipv4 : cidrsubnet(cidr, 1, 0)]
|
|
|
|
ipv6 = [for i, cidr in var.network_cidr.ipv6 : cidrsubnet(cidr, 16, 0)]
|
|
|
|
}
|
|
|
|
worker_subnets = {
|
|
|
|
ipv4 = [for i, cidr in var.network_cidr.ipv4 : cidrsubnet(cidr, 1, 1)]
|
|
|
|
ipv6 = [for i, cidr in var.network_cidr.ipv6 : cidrsubnet(cidr, 16, 1)]
|
|
|
|
}
|
|
|
|
cluster_subnets = {
|
|
|
|
ipv4 = concat(local.controller_subnets.ipv4, local.worker_subnets.ipv4)
|
|
|
|
ipv6 = concat(local.controller_subnets.ipv6, local.worker_subnets.ipv6)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
# Organize cluster into a resource group
|
|
|
|
resource "azurerm_resource_group" "cluster" {
|
2019-05-28 06:43:08 +02:00
|
|
|
name = var.cluster_name
|
|
|
|
location = var.region
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
resource "azurerm_virtual_network" "network" {
|
2024-07-06 02:21:50 +02:00
|
|
|
name = var.cluster_name
|
2019-05-28 06:43:08 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2024-07-06 02:21:50 +02:00
|
|
|
location = azurerm_resource_group.cluster.location
|
|
|
|
address_space = concat(
|
|
|
|
var.network_cidr.ipv4,
|
|
|
|
var.network_cidr.ipv6
|
|
|
|
)
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2024-07-06 02:21:50 +02:00
|
|
|
# Subnets - separate subnets for controllers and workers because Azure
|
|
|
|
# network security groups are oriented around address prefixes rather
|
|
|
|
# than instance tags (GCP) or security group membership (AWS)
|
2018-08-20 03:48:22 +02:00
|
|
|
|
|
|
|
resource "azurerm_subnet" "controller" {
|
|
|
|
name = "controller"
|
2024-07-06 02:21:50 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2019-05-28 06:43:08 +02:00
|
|
|
virtual_network_name = azurerm_virtual_network.network.name
|
2024-07-06 02:21:50 +02:00
|
|
|
address_prefixes = concat(
|
|
|
|
local.controller_subnets.ipv4,
|
|
|
|
local.controller_subnets.ipv6,
|
|
|
|
)
|
|
|
|
default_outbound_access_enabled = false
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
resource "azurerm_subnet_network_security_group_association" "controller" {
|
|
|
|
subnet_id = azurerm_subnet.controller.id
|
|
|
|
network_security_group_id = azurerm_network_security_group.controller.id
|
|
|
|
}
|
|
|
|
|
2018-08-20 03:48:22 +02:00
|
|
|
resource "azurerm_subnet" "worker" {
|
|
|
|
name = "worker"
|
2024-07-06 02:21:50 +02:00
|
|
|
resource_group_name = azurerm_resource_group.cluster.name
|
2019-05-28 06:43:08 +02:00
|
|
|
virtual_network_name = azurerm_virtual_network.network.name
|
2024-07-06 02:21:50 +02:00
|
|
|
address_prefixes = concat(
|
|
|
|
local.worker_subnets.ipv4,
|
|
|
|
local.worker_subnets.ipv6,
|
|
|
|
)
|
|
|
|
default_outbound_access_enabled = false
|
2018-08-20 03:48:22 +02:00
|
|
|
}
|
2019-05-28 06:43:08 +02:00
|
|
|
|
2020-03-08 03:40:39 +01:00
|
|
|
resource "azurerm_subnet_network_security_group_association" "worker" {
|
|
|
|
subnet_id = azurerm_subnet.worker.id
|
|
|
|
network_security_group_id = azurerm_network_security_group.worker.id
|
|
|
|
}
|