forked from miqdigital/terraform-aws-eks-cluster
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy patheks-vpc.tf
executable file
·112 lines (82 loc) · 2.35 KB
/
eks-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
#
# EKS VPC Resources
# * VPC
# * Subnets
# * Internet Gateway
# * Route Table
#
resource "aws_vpc" "eks" {
cidr_block = "10.15.0.0/19"
enable_dns_hostnames = true
tags = {
"Name" = "eks-vpc"
"kubernetes.io/cluster/${var.cluster-name}" = "shared"
}
}
## EKS public subnets
resource "aws_subnet" "eks-public" {
count = "${length(var.public_subnets)}"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
cidr_block = "${var.public_subnets[count.index]}"
vpc_id = "${aws_vpc.eks.id}"
tags = {
"Name" = "eks-public-subnet",
"kubernetes.io/cluster/${var.cluster-name}" = "shared",
}
}
## internet gateway
resource "aws_internet_gateway" "eks-igw" {
vpc_id = "${aws_vpc.eks.id}"
tags = {
Name = "eks-internet-gateway"
}
}
resource "aws_route_table" "eks-public" {
vpc_id = aws_vpc.eks.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.eks-igw.id}"
}
}
resource "aws_route_table_association" "eks" {
count = "${length(var.public_subnets)}"
subnet_id = "${aws_subnet.eks-public.*.id[count.index]}"
route_table_id = "${aws_route_table.eks-public.id}"
}
## EKS private subnets
## NAT gateway
## routing table, routing table association
resource "aws_subnet" "eks-private" {
count = "${length(var.private_subnets)}"
availability_zone = "${data.aws_availability_zones.available.names[count.index]}"
cidr_block = "${var.private_subnets[count.index]}"
vpc_id = "${aws_vpc.eks.id}"
tags = {
"Name" = "eks-private-subnet",
"kubernetes.io/cluster/${var.cluster-name}" = "shared",
"kubernetes.io/role/internal-elb" = "1",
}
}
resource "aws_eip" "nat" {
vpc = true
}
resource "aws_nat_gateway" "nat_gw" {
count = 1
allocation_id = "${aws_eip.nat.id}"
subnet_id = "${aws_subnet.eks-public.*.id[count.index]}" #public subnet
depends_on = [aws_internet_gateway.eks-igw]
tags = {
Name = "gw NAT"
}
}
resource "aws_route_table" "eks-private" {
vpc_id = "${aws_vpc.eks.id}"
tags = {
Name = "route table for private subnets"
}
}
resource "aws_route_table_association" "eks-private" {
count = "${length(var.private_subnets)}"
subnet_id = "${aws_subnet.eks-private.*.id[count.index]}"
route_table_id = "${aws_route_table.eks-private.id}"
}