-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathVPC.tf
145 lines (112 loc) · 2.99 KB
/
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
######################################################################################
# VIRTUAL PRIVATE CLOUD AND ALL IT'S COMPONENTS
######################################################################################
# Terraform Provider
provider "aws" {
region = var.region
}
# The VPC Resource
resource "aws_vpc" "demo_vpc" {
cidr_block = "10.0.0.0/16"
tags = {
Name = "demo_vpc"
}
}
# The Private Subnets
resource "aws_subnet" "private_subnet_1a" {
vpc_id = aws_vpc.demo_vpc.id
cidr_block = "10.0.0.0/19"
availability_zone = var.availablity_zone1
tags = {
Name = "private_subnet_1a"
}
}
resource "aws_subnet" "private_subnet_1b" {
vpc_id = aws_vpc.demo_vpc.id
cidr_block = "10.0.32.0/19"
availability_zone = var.availablity_zone2
tags = {
Name = "private_subnet_1b"
}
}
# The Public Subnets
resource "aws_subnet" "public_subnet_1a" {
vpc_id = aws_vpc.demo_vpc.id
cidr_block = "10.0.64.0/19"
availability_zone = var.availablity_zone1
map_public_ip_on_launch = true
tags = {
Name = "public_subnet_1a"
}
}
resource "aws_subnet" "public_subnet_1b" {
vpc_id = aws_vpc.demo_vpc.id
cidr_block = "10.0.96.0/19"
availability_zone = var.availablity_zone2
map_public_ip_on_launch = true
tags = {
Name = "public_subnet_1b"
}
}
# The Private AWS Route Table
resource "aws_route_table" "private" {
vpc_id = aws_vpc.demo_vpc.id
route {
cidr_block = var.cidr_block
nat_gateway_id = aws_nat_gateway.demo_nat.id
}
tags = {
Name = "private"
}
}
# The Public AWS Route Table
resource "aws_route_table" "public" {
vpc_id = aws_vpc.demo_vpc.id
route {
cidr_block = var.cidr_block
gateway_id = aws_internet_gateway.demo_igw.id
}
tags = {
Name = "public"
}
}
# The Route Table associations
resource "aws_route_table_association" "private_subnet_1a" {
subnet_id = aws_subnet.private_subnet_1a.id
route_table_id = aws_route_table.private.id
}
resource "aws_route_table_association" "private_subnet_1b" {
subnet_id = aws_subnet.private_subnet_1b.id
route_table_id = aws_route_table.private.id
}
resource "aws_route_table_association" "public_subnet_1a" {
subnet_id = aws_subnet.public_subnet_1a.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "public_subnet_1b" {
subnet_id = aws_subnet.public_subnet_1b.id
route_table_id = aws_route_table.public.id
}
# The Elastic IP Resource
resource "aws_eip" "demo_eip" {
vpc = true
tags = {
Name = "demo_eip"
}
}
# The NAT Gateway
resource "aws_nat_gateway" "demo_nat" {
allocation_id = aws_eip.demo_eip.id
subnet_id = aws_subnet.public_subnet_1a.id
tags = {
Name = "demo_nat"
}
depends_on = [aws_internet_gateway.demo_igw]
}
# The Internet Gateway
resource "aws_internet_gateway" "demo_igw" {
vpc_id = aws_vpc.demo_vpc.id
tags = {
Name = "demo_igw"
}
}