-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathsubnet.tf
More file actions
48 lines (45 loc) · 2.04 KB
/
subnet.tf
File metadata and controls
48 lines (45 loc) · 2.04 KB
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
##############################################################################
# Subnet Values
##############################################################################
locals {
# Convert subnets into a single list
subnet_list = flatten([
# For each key in the object create an array
for zone in [for zone in keys(var.subnets) : zone if var.subnets[zone] != null] :
# Each item in the list contains information about a single subnet
[
for value in var.subnets[zone] :
{
name = value.name
resource_name = (var.prefix != null ? "${var.prefix}-${value.name}" : value.name)
prefix_name = "${var.prefix}-${value.name}" # Creates a name of the prefix and subnet name
zone = index(keys(var.subnets), zone) + 1 # Zone 1, 2, or 3
zone_name = "${var.region}-${index(keys(var.subnets), zone) + 1}" # Contains region and zone
cidr = value.cidr # CIDR Block
no_prefix = value.no_addr_prefix # If true will not create addr prefix for subnet under any circumstance
count = index(var.subnets[zone], value) + 1 # Count of the subnet within the zone
acl = value.acl_name
# Public gateway ID
public_gateway = (
lookup(value, "public_gateway", null) == true && lookup(var.use_public_gateways, zone, null) != null
? (
lookup(var.public_gateways, zone, null) == null ? null : var.public_gateways[zone].id
)
: null
)
}
]
])
# Convert list to map
subnet_map = {
for subnet in local.subnet_list :
"${subnet.zone}-${subnet.name}" => merge(
subnet,
{
subnet_id = "${subnet.zone}-${subnet.name}",
resource_name = var.prefix != null ? "${var.prefix}-${subnet.name}" : subnet.name
}
)
}
}
##############################################################################