-
Notifications
You must be signed in to change notification settings - Fork 16
/
edge_vpc.tf
101 lines (86 loc) · 2.8 KB
/
edge_vpc.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
resource "aws_vpc" "edge_sg_vpc" {
cidr_block = var.edge_sg_vpc_cidr
tags = {
Name = "Edge VPC"
}
}
# Create an IGW
resource "aws_internet_gateway" "edge_vpc_igw" {
vpc_id = aws_vpc.edge_sg_vpc.id
}
# Define a NAT subnet primary availability zone
resource "aws_subnet" "edge_external_subnet_1a" {
vpc_id = aws_vpc.edge_sg_vpc.id
cidr_block = "10.7.0.0/24"
map_public_ip_on_launch = false
availability_zone = "${var.region}a"
tags = {
Name = "Edge_VPC_External_Subnet_1A"
}
}
# Define a NAT subnet primary availability zone
resource "aws_subnet" "edge_internal_subnet_1a" {
vpc_id = aws_vpc.edge_sg_vpc.id
cidr_block = "10.7.1.0/24"
map_public_ip_on_launch = false
availability_zone = "${var.region}a"
tags = {
Name = "Edge_VPC_Internal_Subnet_1A"
}
}
# Define a Web server Internal subnet
resource "aws_subnet" "edge_web_subnet_1a" {
vpc_id = aws_vpc.edge_sg_vpc.id
cidr_block = "10.7.5.0/24"
map_public_ip_on_launch = false
availability_zone = "${var.region}a"
tags = {
Name = "Edge_VPC_Web_Subnet_1A"
}
}
# Attach TGW to Edge VPC
resource "aws_ec2_transit_gateway_vpc_attachment" "tgw_attach_edge" {
subnet_ids = [aws_subnet.edge_internal_subnet_1a.id ]
transit_gateway_id = aws_ec2_transit_gateway.demo_tgw.id
vpc_id = aws_vpc.edge_sg_vpc.id
}
# Create a Public route table
resource "aws_route_table" "edge_pub_rt" {
vpc_id = aws_vpc.edge_sg_vpc.id
# Route to the internet
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.edge_vpc_igw.id
}
tags = {
Name = "Edge_VPC_Public_Route_Table"
}
}
resource "aws_route_table_association" "edge_rt_associatio_1a" {
subnet_id = aws_subnet.edge_external_subnet_1a.id
route_table_id = aws_route_table.edge_pub_rt.id
}
# Create Internal Route Table
resource "aws_route_table" "edge_internal_rt" {
vpc_id = aws_vpc.edge_sg_vpc.id
}
# Create Default route
resource "aws_route" "defaultroute" {
route_table_id = aws_route_table.edge_internal_rt.id
destination_cidr_block = "0.0.0.0/0"
network_interface_id = aws_network_interface.nat_nic2.id
#instance_id = aws_instance.vpc_edge_web1.id
}
resource "aws_route_table_association" "nat_internal_association" {
subnet_id = aws_subnet.edge_internal_subnet_1a.id
route_table_id = aws_route_table.edge_internal_rt.id
}
resource "aws_route_table_association" "web_sub_association" {
subnet_id = aws_subnet.edge_web_subnet_1a.id
route_table_id = aws_route_table.edge_internal_rt.id
}
resource "aws_route" "edge_vpcroutes" {
route_table_id = aws_route_table.edge_internal_rt.id
destination_cidr_block = "10.0.0.0/8"
transit_gateway_id = aws_ec2_transit_gateway.demo_tgw.id
}