-
Notifications
You must be signed in to change notification settings - Fork 0
/
01-infrastructure.tf
355 lines (309 loc) · 14.3 KB
/
01-infrastructure.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
module "infrastructure" {
source = "git::https://github.com/statcan/terraform-statcan-azure-cloud-native-environment-infrastructure.git?ref=v1.0.8"
prefix = local.prefix
tags = local.azure_tags
location = var.azure_region
kubernetes_version = var.kubernetes_version
# Administrative groups
resource_owners = var.resource_owners
# Availability zones
availability_zones = var.azure_availability_zones
# Networking
cluster_private_cluster = false
cluster_subnet_id = module.network.aks_system_subnet_id
cluster_authorized_ip_ranges = concat(["${module.network.egress_ip}/32"], var.cluster_authorized_ip_ranges)
# Infrastructure pipeline network
infrastructure_pipeline_allowed_ip_ranges = var.infrastructure_authorized_ip_ranges
infrastructure_pipeline_subnet_ids = var.infrastructure_pipeline_subnet_ids
# Set this to some unusable range
cluster_docker_bridge_cidr = "127.255.255.1/24"
# Use the last /16 in our /14 for the service subnet
cluster_service_cidr = "${var.network_start.first}.${var.network_start.second + 3}.0.0/16"
cluster_dns_service_ip = "${var.network_start.first}.${var.network_start.second + 3}.0.10"
network_policy = var.network_policy
# Nodes
system_node_pool_kubernetes_version = var.system_node_pool_kubernetes_version
system_node_pool_enable_auto_scaling = true
system_node_pool_vm_size = var.system_node_pool_vm_size
system_node_pool_auto_scaling_min_nodes = var.system_node_pool_auto_scaling_min_nodes
system_node_pool_auto_scaling_max_nodes = var.system_node_pool_auto_scaling_max_nodes
# We don't want the general node pool, so set the count to 0.
general_node_pool_kubernetes_version = var.system_general_node_pool_kubernetes_version
general_node_pool_enable_auto_scaling = true
general_node_pool_vm_size = var.system_general_node_pool_vm_size
general_node_pool_auto_scaling_min_nodes = var.system_general_node_pool_auto_scaling_min_nodes
general_node_pool_auto_scaling_max_nodes = var.system_general_node_pool_auto_scaling_max_nodes
general_node_pool_max_pods = var.system_general_node_pool_max_pods
general_node_pool_labels = {
"node.statcan.gc.ca/purpose" = "system"
"node.statcan.gc.ca/use" = "general"
"data.statcan.gc.ca/classification" = "protected-b"
}
general_node_pool_taints = [
"node.statcan.gc.ca/purpose=system:NoSchedule",
"node.statcan.gc.ca/use=general:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
# CSI Drivers
storage_profile = var.storage_profile
# SSH Key
cluster_ssh_key = var.cluster_ssh_key
# Cluster RBAC
cluster_users = var.cluster_users
cluster_admins = var.cluster_admins
}
# Grant access to the entire Vnet
resource "azurerm_role_assignment" "aks_network_add_aks" {
scope = module.network.aks_virtual_network_id
role_definition_name = "Network Add"
principal_id = module.infrastructure.aks_principal_id
}
# Lookup control plane IP
data "dns_a_record_set" "control_plane_ip" {
host = module.infrastructure.cluster_fqdn
}
resource "azurerm_firewall_policy_rule_collection_group" "aks" {
name = "${local.prefix}-fwprcg-aks-control-plane"
firewall_policy_id = module.network.firewall_policy_id
priority = 150
network_rule_collection {
name = "aks-control-plane"
priority = 150
action = "Allow"
rule {
name = "aks-control-plane"
source_addresses = module.network.aks_address_space
destination_addresses = data.dns_a_record_set.control_plane_ip.addrs
destination_ports = ["443"]
protocols = ["TCP"]
}
}
}
module "user_unclassified_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "useruc"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_unclassified_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_availability_zones
vm_size = var.prefixes.environment == "prod" ? "Standard_D64as_v5" : "Standard_D16s_v3"
max_pods = var.user_unclassified_node_pool_max_pods
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "general"
"data.statcan.gc.ca/classification" = "unclassified"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"data.statcan.gc.ca/classification=unclassified:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_unclassified_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_unclassified_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_unclassified_node_pool_auto_scaling_max_nodes
}
module "user_gpu_unclassified_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usergpuuc"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_gpu_unclassified_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_NC6s_v3"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "gpu"
"data.statcan.gc.ca/classification" = "unclassified"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=gpu:NoSchedule",
"data.statcan.gc.ca/classification=unclassified:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_unclassified_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_gpu_unclassified_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_gpu_unclassified_node_pool_auto_scaling_max_nodes
}
module "user_protected_b_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "userpb"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_protected_b_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_availability_zones
vm_size = "Standard_D16s_v3"
max_pods = var.user_protected_b_node_pool_max_pods
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "general"
"data.statcan.gc.ca/classification" = "protected-b"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_protected_b_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_protected_b_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_protected_b_node_pool_auto_scaling_max_nodes
}
module "cloud_main_system_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "cloudmainsys"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.cloud_main_system_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_availability_zones
vm_size = "Standard_D16s_v3"
labels = {
"node.statcan.gc.ca/purpose" = "system"
"node.statcan.gc.ca/use" = "cloud-main-system"
"data.statcan.gc.ca/classification" = "protected-b"
}
taints = [
"node.statcan.gc.ca/purpose=system:NoSchedule",
"node.statcan.gc.ca/use=cloud-main-system:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_cloud_main_system_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.cloud_main_system_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.cloud_main_system_node_pool_auto_scaling_max_nodes
}
module "user_gpu_protected__node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usergpupb"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_gpu_protected_b_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_NC6s_v3"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "gpu"
"data.statcan.gc.ca/classification" = "protected-b"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=gpu:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_protected_b_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_gpu_protected_b_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_gpu_protected_b_node_pool_auto_scaling_max_nodes
}
module "user_gpufour_protected__node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usergpu4pb"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_gpu_protected_b_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_NC24s_v3"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "gpu-4"
"data.statcan.gc.ca/classification" = "protected-b"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=gpu-4:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_protected_b_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_gpu_four_protected_b_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_gpu_four_protected_b_node_pool_auto_scaling_max_nodes
}
module "user_gpufour_unclassified__node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usergpu4uc"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_gpu_protected_b_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_NC24s_v3"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "gpu-4"
"data.statcan.gc.ca/classification" = "unclassified"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=gpu-4:NoSchedule",
"data.statcan.gc.ca/classification=unclassified:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_unclassified_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_gpu_four_unclassified_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_gpu_four_unclassified_node_pool_auto_scaling_max_nodes
}
// Unclassified compute-optimized node pool
module "user_compute_optimized_unclassified_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usercpu72uc"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
kubernetes_version = var.user_gpu_unclassified_node_pool_kubernetes_version
node_count = 1 // this gets overwritten
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_F72s_v2"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "cpu-72"
"data.statcan.gc.ca/classification" = "unclassified"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=cpu-72:NoSchedule",
"data.statcan.gc.ca/classification=unclassified:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_unclassified_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_cpu_seventy_two_unclassified_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_cpu_seventy_two_unclassified_node_pool_auto_scaling_max_nodes
}
// Pro-B compute-optimized node pool
module "user_compute_optimized_protected_node_pool" {
source = "git::https://github.com/statcan/terraform-azurerm-kubernetes-cluster-nodepool.git?ref=v1.0.3"
name = "usercpu72pb"
kubernetes_cluster_id = module.infrastructure.kubernetes_cluster_id
// Assumption: we are using same k8s version as other node pools, that's why we're referencing another version here.
kubernetes_version = var.user_gpu_protected_b_node_pool_kubernetes_version
node_count = 1
#availability_zones = var.azure_gpu_availability_zones
vm_size = "Standard_F72s_v2"
labels = {
"node.statcan.gc.ca/purpose" = "user"
"node.statcan.gc.ca/use" = "cpu-72"
"data.statcan.gc.ca/classification" = "protected-b"
}
taints = [
"node.statcan.gc.ca/purpose=user:NoSchedule",
"node.statcan.gc.ca/use=cpu-72:NoSchedule",
"data.statcan.gc.ca/classification=protected-b:NoSchedule"
]
enable_host_encryption = true
subnet_id = module.network.aks_user_protected_b_subnet_id
tags = local.azure_tags
enable_auto_scaling = true
auto_scaling_min_nodes = var.user_cpu_seventy_two_protected_b_node_pool_auto_scaling_min_nodes
auto_scaling_max_nodes = var.user_cpu_seventy_two_protected_b_node_pool_auto_scaling_max_nodes
}