generated from Azure/terraform-azurerm-avm-template
-
Notifications
You must be signed in to change notification settings - Fork 30
/
locals.tf
82 lines (77 loc) · 2.92 KB
/
locals.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
locals {
private_dns_zone_name = try(reverse(split("/", var.private_dns_zone_id))[0], null)
valid_private_dns_zone_regexs = [
"private\\.[a-z0-9]+\\.azmk8s\\.io",
"privatelink\\.[a-z0-9]+\\.azmk8s\\.io",
"[a-zA-Z0-9\\-]{1,32}\\.private\\.[a-z]+\\.azmk8s\\.io",
"[a-zA-Z0-9\\-]{1,32}\\.privatelink\\.[a-z]+\\.azmk8s\\.io",
]
}
locals {
default_node_pool_available_zones = setsubtract(local.zones, local.restricted_zones)
filtered_vms = [
for sku in data.azapi_resource_list.example.output.value :
sku if(sku.resourceType == "virtualMachines" && sku.name == "Standard_D4d_v5")
]
restricted_zones = try(local.filtered_vms[0].restrictions[0].restrictionInfo.zones, [])
zones = local.filtered_vms[0].locationInfo[0].zones
}
locals {
filtered_vms_by_node_pool = {
for pool_name, pool in var.node_pools : pool_name => [
for sku in data.azapi_resource_list.example.output.value :
sku if(sku.resourceType == "virtualMachines" && sku.name == pool.vm_size)
]
}
my_node_pool_zones_by_pool = {
for pool_name, pool in var.node_pools : pool_name => setsubtract(
local.filtered_vms_by_node_pool[pool_name][0].locationInfo[0].zones,
try(local.filtered_vms_by_node_pool[pool_name][0].restrictions[0].restrictionInfo.zones, [])
)
}
zonetagged_node_pools = {
for pool_name, pool in var.node_pools : pool_name => merge(pool, { zones = local.my_node_pool_zones_by_pool[pool_name] })
}
}
locals {
# Flatten a list of var.node_pools and zones
node_pools = flatten([
for pool in local.zonetagged_node_pools : [
for zone in pool.zones : {
# concatenate name and zone trim to 12 characters
name = "${substr(pool.name, 0, 10)}${zone}"
vm_size = pool.vm_size
orchestrator_version = pool.orchestrator_version
max_count = pool.max_count
min_count = pool.min_count
labels = pool.labels
node_taints = pool.node_taints
os_sku = pool.os_sku
mode = pool.mode
os_disk_size_gb = pool.os_disk_size_gb
zone = [zone]
}
]
])
}
locals {
log_analytics_tables = ["AKSAudit", "AKSAuditAdmin", "AKSControlPlane", "ContainerLogV2"]
}
# Helper locals to make the dynamic block more readable
# There are three attributes here to cater for resources that
# support both user and system MIs, only system MIs, and only user MIs
locals {
managed_identities = {
user_assigned = length(var.managed_identities.user_assigned_resource_ids) > 0 ? {
this = {
type = "UserAssigned"
user_assigned_resource_ids = var.managed_identities.user_assigned_resource_ids
}
} : {
this = {
type = "UserAssigned"
user_assigned_resource_ids = azurerm_user_assigned_identity.aks[*].id
}
}
}
}