Skip to content

Commit f373217

Browse files
authored
feat: (IAC-651) add ability to set pod_cidr and service_cidr while using kubenet (#246)
1 parent 060743c commit f373217

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

modules/azure_aks/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,10 @@ resource "azurerm_kubernetes_cluster" "aks" {
2929
# https://docs.microsoft.com/en-us/azure/aks/load-balancer-standard
3030
# https://docs.microsoft.com/en-us/azure/aks/egress-outboundtype
3131

32-
service_cidr = var.aks_network_plugin == "kubenet" ? "10.0.0.0/16" : var.aks_service_cidr
33-
dns_service_ip = var.aks_network_plugin == "kubenet" ? "10.0.0.10" : var.aks_dns_service_ip
34-
pod_cidr = var.aks_network_plugin == "kubenet" ? "10.244.0.0/16" : null
35-
docker_bridge_cidr = var.aks_network_plugin == "kubenet" ? "172.17.0.1/16" : var.aks_docker_bridge_cidr
32+
service_cidr = var.aks_service_cidr
33+
dns_service_ip = var.aks_dns_service_ip
34+
pod_cidr = var.aks_network_plugin == "kubenet" ? var.aks_pod_cidr : null
35+
docker_bridge_cidr = var.aks_docker_bridge_cidr
3636
outbound_type = var.cluster_egress_type
3737
load_balancer_sku = "standard"
3838
}

modules/azure_aks/variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,21 +97,41 @@ variable "aks_dns_service_ip" {
9797
description = "IP address within the Kubernetes service address range that will be used by cluster service discovery (kube-dns). Changing this forces a new resource to be created."
9898
type = string
9999
default = "10.0.0.10"
100+
validation {
101+
condition = var.aks_dns_service_ip != null ? can(regex("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",var.aks_dns_service_ip)) : false
102+
error_message = "ERROR: aks_dns_service_ip - value must not be null and must be a valid IP address."
103+
}
104+
100105
}
101106

102107
variable "aks_docker_bridge_cidr" {
103108
description = "IP address (in CIDR notation) used as the Docker bridge IP address on nodes. Changing this forces a new resource to be created."
104109
default = "172.17.0.1/16"
110+
validation {
111+
condition = var.aks_docker_bridge_cidr != null ? can(cidrnetmask(var.aks_docker_bridge_cidr)) : false
112+
error_message = "ERROR: aks_docker_bridge_cidr - value must not be null and must be valid CIDR."
113+
}
114+
105115
}
106116

107117
variable "aks_pod_cidr" {
108118
description = "The CIDR to use for pod IP addresses. This field can only be set when network_plugin is set to kubenet. Changing this forces a new resource to be created."
109119
default = "10.244.0.0/16"
120+
validation {
121+
condition = var.aks_pod_cidr != "" ? can(cidrnetmask(var.aks_pod_cidr)) : true
122+
error_message = "ERROR: aks_pod_cidr - value must either be null or must be a valid CIDR."
123+
}
124+
110125
}
111126

112127
variable "aks_service_cidr" {
113128
description = "The Network Range used by the Kubernetes service. Changing this forces a new resource to be created."
114129
default = "10.0.0.0/16"
130+
validation {
131+
condition = var.aks_service_cidr != null ? can(cidrnetmask(var.aks_service_cidr)) : false
132+
error_message = "ERROR: aks_service_cidr - value must not be null and must be a valid CIDR."
133+
}
134+
115135
}
116136

117137
variable "aks_cluster_tags" {

variables.tf

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,21 @@ variable "aks_dns_service_ip" {
147147
description = "IP address within the Kubernetes service address range that will be used by cluster service discovery (kube-dns). Changing this forces a new resource to be created."
148148
type = string
149149
default = "10.0.0.10"
150+
validation {
151+
condition = var.aks_dns_service_ip != null ? can(regex("^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$",var.aks_dns_service_ip)) : false
152+
error_message = "ERROR: aks_dns_service_ip - value must not be null and must be a valid IP address."
153+
}
154+
150155
}
151156

152157
variable "aks_docker_bridge_cidr" {
153158
description = "IP address (in CIDR notation) used as the Docker bridge IP address on nodes. Changing this forces a new resource to be created."
154159
default = "172.17.0.1/16"
160+
validation {
161+
condition = var.aks_docker_bridge_cidr != null ? can(cidrnetmask(var.aks_docker_bridge_cidr)) : false
162+
error_message = "ERROR: aks_docker_bridge_cidr - value must not be null and must be valid CIDR."
163+
}
164+
155165
}
156166

157167
variable "cluster_egress_type" {
@@ -166,11 +176,21 @@ variable "cluster_egress_type" {
166176
variable "aks_pod_cidr" {
167177
description = "The CIDR to use for pod IP addresses. This field can only be set when network_plugin is set to kubenet. Changing this forces a new resource to be created."
168178
default = "10.244.0.0/16"
179+
validation {
180+
condition = var.aks_pod_cidr != "" ? can(cidrnetmask(var.aks_pod_cidr)) : true
181+
error_message = "ERROR: aks_pod_cidr - value must either be null or must be a valid CIDR."
182+
}
183+
169184
}
170185

171186
variable "aks_service_cidr" {
172187
description = "The Network Range used by the Kubernetes service. Changing this forces a new resource to be created."
173188
default = "10.0.0.0/16"
189+
validation {
190+
condition = var.aks_service_cidr != null ? can(cidrnetmask(var.aks_service_cidr)) : false
191+
error_message = "ERROR: aks_service_cidr - value must not be null and must be a valid CIDR."
192+
}
193+
174194
}
175195

176196
variable "aks_uai_name" {

0 commit comments

Comments
 (0)