-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpublic-subnets.tf
More file actions
60 lines (52 loc) · 1.85 KB
/
public-subnets.tf
File metadata and controls
60 lines (52 loc) · 1.85 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
49
50
51
52
53
54
55
56
57
58
59
60
resource "aws_subnet" "primary_public" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.primary_public_subnet_cidr_block
ipv6_cidr_block = local.ipv6_cidrs[2]
map_public_ip_on_launch = true
assign_ipv6_address_on_creation = true
availability_zone = "${var.region}a"
tags = {
Name = "${var.basename}-primary-public"
}
}
resource "aws_subnet" "secondary_public" {
vpc_id = aws_vpc.vpc.id
cidr_block = var.secondary_public_subnet_cidr_block
ipv6_cidr_block = local.ipv6_cidrs[3]
map_public_ip_on_launch = true
assign_ipv6_address_on_creation = true
availability_zone = "${var.region}b"
tags = {
Name = "${var.basename}-secondary-public"
}
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.basename}-igw"
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.vpc.id
tags = {
Name = "${var.basename}-public-subnets"
}
}
resource "aws_route" "ipv4_egress_from_public_subnets_to_internet" {
route_table_id = aws_route_table.public.id
destination_cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
resource "aws_route" "ipv6_egress_from_public_subnets_to_internet" {
route_table_id = aws_route_table.public.id
destination_ipv6_cidr_block = "::/0"
gateway_id = aws_internet_gateway.igw.id
}
resource "aws_route_table_association" "primary_public" {
subnet_id = aws_subnet.primary_public.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "secondary_public" {
subnet_id = aws_subnet.secondary_public.id
route_table_id = aws_route_table.public.id
}