-
Notifications
You must be signed in to change notification settings - Fork 15
/
private_subnets.tf
38 lines (33 loc) · 1.38 KB
/
private_subnets.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
resource "aws_subnet" "private" {
vpc_id = aws_vpc.base.id
count = length(var.availability_zones)
cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index + length(var.availability_zones) + local.private_subnets_offset)
availability_zone = element(var.availability_zones, count.index)
tags = {
Name = "private-subnet-${var.component}-${var.deployment_identifier}-${element(var.availability_zones, count.index)}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Tier = "private"
}
}
resource "aws_route_table" "private" {
vpc_id = aws_vpc.base.id
count = length(var.availability_zones)
tags = {
Name = "private-routetable-${var.component}-${var.deployment_identifier}-${element(var.availability_zones, count.index)}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Tier = "private"
}
}
resource "aws_route" "private_internet" {
count = local.include_nat_gateways == "yes" ? length(var.availability_zones) : 0
route_table_id = element(aws_route_table.private.*.id, count.index)
nat_gateway_id = element(aws_nat_gateway.base.*.id, count.index)
destination_cidr_block = "0.0.0.0/0"
}
resource "aws_route_table_association" "private" {
count = length(var.availability_zones)
subnet_id = element(aws_subnet.private.*.id, count.index)
route_table_id = element(aws_route_table.private.*.id, count.index)
}