forked from MithunTechnologiesDevOps/EKS-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvpc.tf
111 lines (84 loc) · 2.9 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
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr
instance_tenancy = "default"
enable_dns_hostnames = true
enable_dns_support = true
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-vpc",
"kubernetes.io/cluster/${var.project_name}-cluster}" = "shared"
})
}
resource "aws_subnet" "public" {
count = length(var.public_subnet_cidrs)
vpc_id = aws_vpc.main.id
cidr_block = element(var.public_subnet_cidrs, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
map_public_ip_on_launch = true
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-public-subnet",
"kubernetes.io/cluster/${var.project_name}-cluster}" = "shared",
"kubernetes.io/role/elb" = "1"
})
}
resource "aws_subnet" "private" {
count = length(var.private_subnet_cidrs)
vpc_id = aws_vpc.main.id
cidr_block = element(var.private_subnet_cidrs, count.index)
availability_zone = data.aws_availability_zones.available.names[count.index]
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-private-subnet",
"kubernetes.io/cluster/${var.project_name}-cluster}" = "shared",
"kubernetes.io/role/internal-elb" = "1"
})
}
resource "aws_internet_gateway" "igw" {
vpc_id = aws_vpc.main.id
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-igw"
})
}
resource "aws_route_table" "public_rt" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.igw.id
}
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-public-rt"
})
}
resource "aws_route_table_association" "public_rt_assocation" {
count = length(var.public_subnet_cidrs)
route_table_id = aws_route_table.public_rt.id
subnet_id = aws_subnet.public[count.index].id
}
resource "aws_eip" "nateip" {
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-nateip"
})
}
resource "aws_nat_gateway" "nat_gateway" {
allocation_id = aws_eip.nateip.id
subnet_id = aws_subnet.public[0].id
depends_on = [
aws_internet_gateway.igw
]
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-nat"
})
}
resource "aws_route_table" "private_rt" {
vpc_id = aws_vpc.main.id
route {
cidr_block = "0.0.0.0/0"
nat_gateway_id = aws_nat_gateway.nat_gateway.id
}
tags = merge(var.common_tags, {
"Name" = "${var.project_name}-private-rt"
})
}
resource "aws_route_table_association" "private_rt_assocation" {
count = length(var.private_subnet_cidrs)
route_table_id = aws_route_table.private_rt.id
subnet_id = aws_subnet.private[count.index].id
}