-
Notifications
You must be signed in to change notification settings - Fork 1
/
locals.tf
64 lines (54 loc) · 2.42 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
locals {
az_mapping = {
for idx, az in data.aws_availability_zones.available.names : az =>
data.aws_availability_zones.available.zone_ids[idx]
}
az_id_to_az = { for az, az_id in local.az_mapping : az_id => az }
normalized_public_subnets_all = {
for k, v in var.subnets.public : k => merge(v, {
az = lookup(local.az_id_to_az, v.az, v.az) # modify AZ ID to AZ
})
}
normalized_private_subnets_all = {
for k, v in var.subnets.private : k => merge(v, {
az = lookup(local.az_id_to_az, v.az, v.az) # modify AZ ID to AZ
})
}
# group by type and create a list of identifiers
private_subnets_by_type = {
for type in distinct([for k, v in local.normalized_private_subnets_all : v.type]) : type => {
ids = [for k, v in local.normalized_private_subnets_all : aws_subnet.private[k].id if v.type == type]
keys = [for k, v in local.normalized_private_subnets_all : k if v.type == type]
}
}
public_subnets_by_type = {
for type in distinct([for k, v in var.subnets.public : v.type]) : type => {
ids = [for k, v in local.normalized_public_subnets_all : aws_subnet.public[k].id if v.type == type]
keys = [for k, v in local.normalized_public_subnets_all : k if v.type == type]
}
}
private_subnets_by_az_output = {
for az in distinct([for subnet in local.normalized_private_subnets_all : subnet.az]) : az => [
for subnet_key, subnet in local.normalized_private_subnets_all : aws_subnet.private[subnet_key].id
if subnet.az == az
]
}
public_subnets_by_az_output = {
for az in distinct([for subnet in local.normalized_public_subnets_all : subnet.az]) : az => [
for subnet_key, subnet in local.normalized_public_subnets_all : aws_subnet.public[subnet_key].id
if subnet.az == az
]
}
private_subnets_by_az_id = {
for az_id in distinct([for subnet in local.normalized_private_subnets_all : lookup(local.az_mapping, subnet.az)]) : az_id => [
for subnet_key, subnet in local.normalized_private_subnets_all : aws_subnet.private[subnet_key].id
if lookup(local.az_mapping, subnet.az) == az_id
]
}
public_subnets_by_az_id = {
for az_id in distinct([for subnet in local.normalized_public_subnets_all : lookup(local.az_mapping, subnet.az)]) : az_id => [
for subnet_key, subnet in local.normalized_public_subnets_all : aws_subnet.public[subnet_key].id
if lookup(local.az_mapping, subnet.az) == az_id
]
}
}