-
Notifications
You must be signed in to change notification settings - Fork 1
/
public-network.tf
87 lines (80 loc) · 2.99 KB
/
public-network.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
#AWS resource to create a VPC CIDR Block and to enable a DNS hostname to the instances
resource "aws_vpc" "boundary_ingress_worker_vpc" {
cidr_block = var.aws_vpc_cidr
enable_dns_hostnames = true
tags = {
Name = "Boundary Ingress Worker Public VPC CIDR Block"
}
}
# Create a Public subnet and assign to the VPC. The NAT gateway will be associated to this subnet
resource "aws_subnet" "boundary_ingress_worker_subnet" {
vpc_id = aws_vpc.boundary_ingress_worker_vpc.id
cidr_block = var.aws_subnet_cidr
map_public_ip_on_launch = true
availability_zone = var.availability_zone
tags = {
Name = "Boundary Ingress Worker Public Subnet"
}
}
# Create a Private suibnet and assign to the VPC.
resource "aws_subnet" "boundary_private_ingress_worker_subnet" {
vpc_id = aws_vpc.boundary_ingress_worker_vpc.id
cidr_block = "172.31.40.0/24"
map_public_ip_on_launch = false
availability_zone = var.availability_zone
tags = {
Name = "Boundary Ingress Worker Private Subnet"
}
}
# AWS resource to create the Internet Gateway
resource "aws_internet_gateway" "boundary_ingress_worker_ig" {
vpc_id = aws_vpc.boundary_ingress_worker_vpc.id
tags = {
Name = "boundary-worker-igw"
}
}
/* AWS resource to create a route table with a default route pointing to the IGW and
a route for the private 192.x.x.x network pointing towards the TGW
*/
resource "aws_route_table" "boundary_ingress_worker_public_rt" {
vpc_id = aws_vpc.boundary_ingress_worker_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.boundary_ingress_worker_ig.id
}
route {
cidr_block = "192.168.0.0/24"
transit_gateway_id = aws_ec2_transit_gateway.boundary_tgw.id
}
tags = {
Name = "boundary-ingress-worker-public-rt"
}
depends_on = [aws_ec2_transit_gateway.boundary_tgw]
}
/* AWS resource to create a route table with a default route pointing to the NAT GW and
a route for the private 192.x.x.x network pointing towards the TGW
*/
resource "aws_route_table" "boundary_ingress_worker_private_rt" {
vpc_id = aws_vpc.boundary_ingress_worker_vpc.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
route {
cidr_block = "192.168.0.0/24"
transit_gateway_id = aws_ec2_transit_gateway.boundary_tgw.id
}
tags = {
Name = "boundary-ingress-worker-private-rt"
}
depends_on = [aws_ec2_transit_gateway.boundary_tgw]
}
# AWS resource to associate the route table to the CIDR blocks created
resource "aws_route_table_association" "boundary_ingress_worker_public_rt_associate" {
subnet_id = aws_subnet.boundary_ingress_worker_subnet.id
route_table_id = aws_route_table.boundary_ingress_worker_public_rt.id
}
resource "aws_route_table_association" "boundary_ingress_worker_private_rt_associate" {
subnet_id = aws_subnet.boundary_private_ingress_worker_subnet.id
route_table_id = aws_route_table.boundary_ingress_worker_private_rt.id
}