-
Notifications
You must be signed in to change notification settings - Fork 0
/
aks.tf
195 lines (171 loc) · 5.49 KB
/
aks.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
resource "random_pet" "aks_name" {
count = var.aks_name == "" ? 1 : 0
}
resource "random_pet" "dns_prefix" {
count = var.dns_prefix == "" ? 1 : 0
}
locals {
random_aks_name = one(random_pet.aks_name[*].id)
random_dns_prefix = one(random_pet.dns_prefix[*].id)
}
resource "azurerm_subnet" "aks_subnet" {
count = var.create_aks_subnet ? 1 : 0
address_prefixes = var.aks_subnet_address_space
name = var.aks_subnet_name
resource_group_name = data.azurerm_resource_group.mappia_rg.name
virtual_network_name = azurerm_virtual_network.mappia_vn.name
}
resource "azurerm_kubernetes_cluster" "mappia_aks" {
name = coalesce(var.aks_name, local.random_aks_name)
location = local.location
resource_group_name = var.resource_group_name
dns_prefix = coalesce(var.dns_prefix, local.random_dns_prefix)
kubernetes_version = var.kubernetes_version
oidc_issuer_enabled = true
dynamic "oms_agent" {
for_each = var.oms_log_analytics_workspace_id != "" ? ["this"] : []
content {
log_analytics_workspace_id = var.oms_log_analytics_workspace_id
msi_auth_for_monitoring_enabled = true
}
}
key_vault_secrets_provider {
secret_rotation_enabled = true
}
identity {
type = "SystemAssigned"
}
network_profile {
network_plugin = var.aks_network_profile.network_plugin
service_cidr = var.aks_network_profile.service_cidr
dns_service_ip = var.aks_network_profile.dns_service_ip
}
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster#default_node_pool
default_node_pool {
name = var.default_node_pool.name
vm_size = var.default_node_pool.vm_size
auto_scaling_enabled = true
max_count = var.default_node_pool.max_count
min_count = var.default_node_pool.min_count
zones = var.default_node_pool.zones
vnet_subnet_id = var.create_aks_subnet ? azurerm_subnet.aks_subnet[0].id : null
temporary_name_for_rotation = "temppool"
dynamic "linux_os_config" {
for_each = var.default_node_pool.set_max_map_count ? ["this"] : []
content {
sysctl_config {
# opensearch required configuration
vm_max_map_count = 262144
}
}
}
}
}
resource "azurerm_kubernetes_cluster_node_pool" "mappia_aks_extra_nodes" {
count = length(var.extra_node_pools)
name = var.extra_node_pools[count.index].name
kubernetes_cluster_id = azurerm_kubernetes_cluster.mappia_aks.id
vm_size = var.extra_node_pools[count.index].vm_size
auto_scaling_enabled = true
max_count = var.extra_node_pools[count.index].max_count
min_count = var.extra_node_pools[count.index].min_count
zones = var.extra_node_pools[count.index].zones
vnet_subnet_id = var.create_aks_subnet ? azurerm_subnet.aks_subnet[0].id : null
node_taints = var.extra_node_pools[count.index].node_taint
dynamic "linux_os_config" {
for_each = var.extra_node_pools[count.index].set_max_map_count ? ["this"] : []
content {
sysctl_config {
# opensearch required configuration
vm_max_map_count = 262144
}
}
}
}
resource "azurerm_public_ip" "mappia_ip" {
name = var.public_ip_name
location = local.location
resource_group_name = var.resource_group_name
allocation_method = "Static"
ip_version = "IPv4"
sku = "Standard"
domain_name_label = coalesce(var.domain_name_label, local.random_domain_name)
zones = var.public_ip_zones
}
resource "azurerm_role_assignment" "aks_identity_ip_role_permission" {
scope = azurerm_public_ip.mappia_ip.id
role_definition_name = "Network Contributor"
principal_id = azurerm_kubernetes_cluster.mappia_aks.identity[0].principal_id
}
resource "kubernetes_storage_class" "mappia_writable" {
depends_on = [
azurerm_kubernetes_cluster.mappia_aks
]
metadata {
name = "azurefile-csi-web-writable"
}
storage_provisioner = "file.csi.azure.com"
volume_binding_mode = "Immediate"
mount_options = [
"dir_mode=0777",
"file_mode=0777",
"gid=82",
"uid=82",
"mfsymlinks",
"cache=strict",
"nosharesock",
]
parameters = {
skuName = "Standard_LRS"
}
}
resource "kubernetes_storage_class" "mappia_writable_premium" {
depends_on = [
azurerm_kubernetes_cluster.mappia_aks
]
metadata {
name = "azurefile-premium-csi-web-writable"
}
storage_provisioner = "file.csi.azure.com"
volume_binding_mode = "Immediate"
mount_options = [
"dir_mode=0777",
"file_mode=0777",
"gid=82",
"uid=82",
"mfsymlinks",
"cache=strict",
"nosharesock",
]
parameters = {
skuName = "Premium_LRS"
}
}
resource "kubernetes_storage_class" "mappia_writable_premium_loose" {
depends_on = [
azurerm_kubernetes_cluster.mappia_aks
]
metadata {
name = "azurefile-premium-csi-web-writable-loose"
}
storage_provisioner = "file.csi.azure.com"
volume_binding_mode = "Immediate"
mount_options = [
"dir_mode=0777",
"file_mode=0777",
"gid=82",
"uid=82",
"mfsymlinks",
"cache=loose",
"nosharesock",
]
parameters = {
skuName = "Premium_LRS"
}
}
resource "random_pet" "domain_name" {
count = var.domain_name_label == "" ? 1 : 0
}
locals {
random_domain_name = one(random_pet.domain_name[*].id)
}