-
Notifications
You must be signed in to change notification settings - Fork 15
/
public_subnets.tf
38 lines (33 loc) · 1.28 KB
/
public_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" "public" {
vpc_id = aws_vpc.base.id
count = length(var.availability_zones)
cidr_block = cidrsubnet(var.vpc_cidr, 8, count.index + local.public_subnets_offset)
availability_zone = element(var.availability_zones, count.index)
tags = {
Name = "public-subnet-${var.component}-${var.deployment_identifier}-${element(var.availability_zones, count.index)}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Tier = "public"
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.base.id
count = length(var.availability_zones)
tags = {
Name = "public-routetable-${var.component}-${var.deployment_identifier}-${element(var.availability_zones, count.index)}"
Component = var.component
DeploymentIdentifier = var.deployment_identifier
Tier = "public"
}
}
resource "aws_route" "public_internet" {
count = length(var.availability_zones)
route_table_id = element(aws_route_table.public.*.id, count.index)
gateway_id = aws_internet_gateway.base_igw.id
destination_cidr_block = "0.0.0.0/0"
}
resource "aws_route_table_association" "public" {
count = length(var.availability_zones)
subnet_id = element(aws_subnet.public.*.id, count.index)
route_table_id = element(aws_route_table.public.*.id, count.index)
}