-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path2.vpc-components.tf
133 lines (106 loc) · 3.5 KB
/
2.vpc-components.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
######################################## SUBNETS ######################################
resource "aws_subnet" "private_sub_a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.0.0/19"
availability_zone = "${var.region}a"
tags = {
"Name" = "${var.projname_short}-private-${var.region}a"
"kubernetes.io/role/internal-elb" = "1"
"kubernetes.io/cluster/${var.projname_short}-cluster" = "owned"
}
}
resource "aws_subnet" "private_sub_b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.32.0/19"
availability_zone = "${var.region}b"
tags = {
"Name" = "${var.projname_short}-private-${var.region}b"
"kubernetes.io/role/internal-elb" = "1"
"kubernetes.io/cluster${var.projname_short}-cluster" = "owned"
}
}
resource "aws_subnet" "public_sub_a" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.64.0/19"
availability_zone = "${var.region}a"
map_public_ip_on_launch = true
tags = {
"Name" = "${var.projname_short}-public-${var.region}a"
"kubernetes.io/role/elb" = "1"
"kubernetes.io/cluster/${var.projname_short}-cluster" = "owned"
}
}
resource "aws_subnet" "public_sub_b" {
vpc_id = aws_vpc.main.id
cidr_block = "10.0.96.0/19"
availability_zone = "${var.region}b"
map_public_ip_on_launch = true
tags = {
"Name" = "${var.projname_short}-public-${var.region}b"
"kubernetes.io/role/elb" = "1"
"kubernetes.io/cluster/${var.projname_short}-cluster" = "owned"
}
}
######################################## GATEWAYS ######################################
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = {
Name = "${var.projname_short}-igw"
}
}
# NAT
resource "aws_eip" "nat" {
vpc = true
tags = {
Name = "${var.projname_short}-nat-eip"
}
}
resource "aws_nat_gateway" "nat" {
allocation_id = aws_eip.nat.id
subnet_id = aws_subnet.public_sub_a.id
tags = {
Name = "${var.projname_short}-nat"
}
depends_on = [aws_internet_gateway.igw]
}
######################################## ROUTES ######################################
resource "aws_route_table" "private" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat.id
}
tags = {
Name = "${var.projname_short}-private-route"
}
}
resource "aws_route_table" "public" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = {
Name = "${var.projname_short}-public-route"
}
}
resource "aws_route_table_association" "private_sub_a" {
subnet_id = aws_subnet.private_sub_a.id
route_table_id = aws_route_table.private.id
}
resource "aws_route_table_association" "private_sub_b" {
subnet_id = aws_subnet.private_sub_b.id
route_table_id = aws_route_table.private.id
}
resource "aws_route_table_association" "public_sub_a" {
subnet_id = aws_subnet.public_sub_a.id
route_table_id = aws_route_table.public.id
}
resource "aws_route_table_association" "public_sub_b" {
subnet_id = aws_subnet.public_sub_b.id
route_table_id = aws_route_table.public.id
}
######################################## OUTPUTS ######################################
output "region" {
value = var.region
}