-
Notifications
You must be signed in to change notification settings - Fork 10
/
cidr.tf
143 lines (116 loc) · 6.3 KB
/
cidr.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
resource "aws_vpc_ipv4_cidr_block_association" "additional_cidr" {
for_each = toset(var.vpc_additional_cidr)
vpc_id = aws_vpc.main.id
cidr_block = each.value
}
# Additional Private Subnets #
resource "aws_subnet" "additional_sn_private_a" {
count = local.additional_sn_private_a
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_private_subnets_a[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 0))
availability_zone = local.az1
tags = merge(
{
Name = local.additional_sn_private_a > 0 ? "${var.additional_sn_private_a_name}${count.index + 2}" : var.additional_sn_private_a_name
},
length(var.additional_sn_private_a_tags) != 0 ? var.additional_sn_private_a_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
resource "aws_subnet" "additional_sn_private_b" {
count = local.additional_sn_private_b
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_private_subnets_b[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 1))
availability_zone = local.az2
tags = merge(
{
Name = local.additional_sn_private_b > 0 ? "${var.additional_sn_private_b_name}${count.index + 2}" : var.additional_sn_private_b_name
},
length(var.additional_sn_private_b_tags) != 0 ? var.additional_sn_private_b_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
resource "aws_subnet" "additional_sn_private_c" {
count = local.additional_sn_private_c
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_private_subnets_c[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 2))
availability_zone = local.az3
tags = merge(
{
Name = local.additional_sn_private_c > 0 ? "${var.additional_sn_private_c_name}${count.index + 2}" : var.additional_sn_private_c_name
},
length(var.additional_sn_private_c_tags) != 0 ? var.additional_sn_private_c_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
# Additional Public Subnets #
resource "aws_subnet" "additional_sn_public_a" {
count = local.additional_sn_public_a
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_public_subnets_a[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 4))
availability_zone = local.az1
tags = merge(
{
Name = local.additional_sn_public_a > 0 ? "${var.additional_sn_public_a_name}${count.index + 2}" : var.additional_sn_public_a_name
},
length(var.additional_sn_public_a_tags) != 0 ? var.additional_sn_public_a_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
resource "aws_subnet" "additional_sn_public_b" {
count = local.additional_sn_public_b
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_public_subnets_b[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 5))
availability_zone = local.az2
tags = merge(
{
Name = local.additional_sn_public_b > 0 ? "${var.additional_sn_public_b_name}${count.index + 2}" : var.additional_sn_public_b_name
},
length(var.additional_sn_public_b_tags) != 0 ? var.additional_sn_public_b_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
resource "aws_subnet" "additional_sn_public_c" {
count = local.additional_sn_public_c
vpc_id = aws_vpc.main.id
cidr_block = (local.enable_additional_dynamic_subnets == true ? var.additional_public_subnets_c[count.index] : cidrsubnet(var.vpc_additional_cidr[count.index], 3, 6))
availability_zone = local.az3
tags = merge(
{
Name = local.additional_sn_public_c > 0 ? "${var.additional_sn_public_c_name}${count.index + 2}" : var.additional_sn_public_c_name
},
length(var.additional_sn_public_c_tags) != 0 ? var.additional_sn_public_c_tags[count.index] : {}
)
depends_on = [aws_vpc_ipv4_cidr_block_association.additional_cidr]
}
# route table associations
resource "aws_route_table_association" "additional_rt_private_a" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_private_a : 1) : 0)
subnet_id = aws_subnet.additional_sn_private_a[count.index].id
route_table_id = aws_route_table.rt_private.id
}
resource "aws_route_table_association" "additional_rt_private_b" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_private_b : 1) : 0)
subnet_id = aws_subnet.additional_sn_private_b[count.index].id
route_table_id = aws_route_table.rt_private.id
}
resource "aws_route_table_association" "additional_rt_private_c" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_private_c : 1) : 0)
subnet_id = aws_subnet.additional_sn_private_c[count.index].id
route_table_id = aws_route_table.rt_private.id
}
resource "aws_route_table_association" "additional_rt_public_a" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_public_a : 1) : 0)
subnet_id = aws_subnet.additional_sn_public_a[count.index].id
route_table_id = aws_route_table.rt_public.id
}
resource "aws_route_table_association" "additional_rt_public_b" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_public_b : 1) : 0)
subnet_id = aws_subnet.additional_sn_public_b[count.index].id
route_table_id = aws_route_table.rt_public.id
}
resource "aws_route_table_association" "additional_rt_public_c" {
count = (length(var.vpc_additional_cidr) > 0 ? (local.enable_additional_dynamic_subnets == true ? local.additional_sn_public_c : 1) : 0)
subnet_id = aws_subnet.additional_sn_public_c[count.index].id
route_table_id = aws_route_table.rt_public.id
}