-
Notifications
You must be signed in to change notification settings - Fork 0
/
vpc.tf
107 lines (84 loc) · 2.56 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
##################################################################################
# VARIABLES
##################################################################################
variable "Custom-VPC_address_space" {
default = "10.1.0.0/16"
}
##################################################################################
# RESOURCES
##################################################################################
# NETWORKING #
resource "aws_vpc" "Custom-VPC" {
cidr_block = "${var.Custom-VPC_address_space}"
enable_dns_support = true
enable_dns_hostnames = true
tags {
Name = "VPC-Custom"
}
}
resource "aws_internet_gateway" "IGW-Custom-VPC" {
vpc_id = "${aws_vpc.Custom-VPC.id}"
tags {
Name = "IGW-VPC-Custom"
}
}
resource "aws_eip" "Custom-VPC-nat_eip" {
vpc = true
depends_on = ["aws_internet_gateway.IGW-Custom-VPC"]
tags {
Name = "VPC-NAT_EIP-Custom"
}
}
resource "aws_nat_gateway" "NATGW-Custom-VPC" {
allocation_id = "${aws_eip.Custom-VPC-nat_eip.id}"
subnet_id = "${aws_subnet.pub_subnet.id}"
tags {
Name = "NATGW-Custom-VPC"
}
depends_on = ["aws_internet_gateway.IGW-Custom-VPC"]
}
resource "aws_subnet" "pub_subnet" {
cidr_block = "${cidrsubnet(var.Custom-VPC_address_space, 8, count.index + 1)}"
vpc_id = "${aws_vpc.Custom-VPC.id}"
map_public_ip_on_launch = "true"
tags {
Name = "pub_subnet-VPC-Custom"
}
}
resource "aws_subnet" "priv_subnet" {
cidr_block = "${cidrsubnet(var.Custom-VPC_address_space, 8, count.index + 3)}"
vpc_id = "${aws_vpc.Custom-VPC.id}"
map_public_ip_on_launch = "false"
tags {
Name = "priv_subnet-VPC-Custom"
}
}
# ROUTING #
resource "aws_route_table" "Custom-VPC-pub-rt" {
vpc_id = "${aws_vpc.Custom-VPC.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.IGW-Custom-VPC.id}"
}
tags {
Name = "pub-rt-VPC-Custom"
}
}
resource "aws_route_table_association" "Custom-VPC-pub-rta" {
subnet_id = "${aws_subnet.pub_subnet.id}"
route_table_id = "${aws_route_table.Custom-VPC-pub-rt.id}"
}
resource "aws_route_table" "Custom-VPC-priv-rt" {
vpc_id = "${aws_vpc.Custom-VPC.id}"
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = "${aws_nat_gateway.NATGW-Custom-VPC.id}"
}
tags {
Name = "priv-rt-VPC-Custom"
}
}
resource "aws_route_table_association" "Custom-VPC-priv-rta" {
subnet_id = "${aws_subnet.priv_subnet.id}"
route_table_id = "${aws_route_table.Custom-VPC-priv-rt.id}"
}