Skip to content

Commit ea03d41

Browse files
Merge pull request #39 from techiescamp/develop
🔀 fargate-app-project
2 parents ea2973f + a193024 commit ea03d41

File tree

10 files changed

+311
-0
lines changed

10 files changed

+311
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: eksctl.io/v1alpha5
2+
kind: ClusterConfig
3+
4+
metadata:
5+
name: pomodoroapp-fargate
6+
region: us-east-1
7+
8+
vpc:
9+
id: "vpc-09cda2c938e687f27"
10+
cidr: "10.0.0.0/16"
11+
subnets:
12+
private:
13+
us-east-1a: { id: subnet-045d0562c6a1d8233 }
14+
us-east-1b: { id: subnet-06dd483abe9150717 }
15+
16+
clusterEndpoints:
17+
publicAccess: false
18+
privateAccess: true
19+
20+
iam:
21+
withOIDC: true
22+
23+
fargateProfiles:
24+
- name: fp-default
25+
selectors:
26+
- namespace: default
27+
- namespace: kube-system
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
apiVersion: eksctl.io/v1alpha5
2+
kind: ClusterConfig
3+
4+
metadata:
5+
name: pomodoroapp-fargate
6+
region: us-east-1
7+
8+
fargateProfiles:
9+
- name: fp-game
10+
selectors:
11+
- namespace: game-ns
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
apiVersion: v2
2+
name: 2048-game
3+
description: A Helm chart to deploy the 2048 game
4+
version: 0.1.0
5+
appVersion: "1.0"
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
namespace: {{ .Values.namespace }}
5+
name: deployment-2048
6+
spec:
7+
selector:
8+
matchLabels:
9+
app.kubernetes.io/name: app-2048
10+
replicas: {{ .Values.replicas }}
11+
template:
12+
metadata:
13+
labels:
14+
app.kubernetes.io/name: app-2048
15+
spec:
16+
containers:
17+
- image: {{ .Values.image.repository }}:{{ .Values.image.tag }}
18+
imagePullPolicy: Always
19+
name: app-2048
20+
ports:
21+
- containerPort: 80
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
namespace: {{ .Values.namespace }}
5+
name: service-2048
6+
annotations:
7+
service.beta.kubernetes.io/aws-load-balancer-nlb-target-type: "ip"
8+
service.beta.kubernetes.io/aws-load-balancer-type: external
9+
service.beta.kubernetes.io/aws-load-balancer-scheme: internet-facing
10+
spec:
11+
ports:
12+
- port: {{ .Values.service.port }}
13+
targetPort: 80
14+
protocol: TCP
15+
type: {{ .Values.service.type }}
16+
selector:
17+
app.kubernetes.io/name: app-2048
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
replicas: 3
2+
image:
3+
repository: public.ecr.aws/l6m2t8p7/docker-2048
4+
tag: latest
5+
service:
6+
port: 80
7+
type: LoadBalancer
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
/*====
2+
The VPC
3+
======*/
4+
5+
resource "aws_vpc" "vpc" {
6+
cidr_block = "${var.vpc_cidr}"
7+
enable_dns_hostnames = true
8+
enable_dns_support = true
9+
10+
tags = {
11+
Name = "${var.environment}-vpc"
12+
Environment = "${var.environment}"
13+
}
14+
}
15+
16+
/*====
17+
Subnets
18+
======*/
19+
/* Internet gateway for the public subnet */
20+
resource "aws_internet_gateway" "ig" {
21+
vpc_id = "${aws_vpc.vpc.id}"
22+
23+
tags = {
24+
Name = "${var.environment}-igw"
25+
Environment = "${var.environment}"
26+
}
27+
}
28+
29+
30+
/* Elastic IP for NAT */
31+
resource "aws_eip" "nat_eip" {
32+
vpc = true
33+
depends_on = [aws_internet_gateway.ig]
34+
}
35+
36+
/* NAT */
37+
resource "aws_nat_gateway" "nat" {
38+
allocation_id = "${aws_eip.nat_eip.id}"
39+
subnet_id = "${element(aws_subnet.public_subnet.*.id, 0)}"
40+
depends_on = [aws_internet_gateway.ig]
41+
42+
tags = {
43+
Name = "nat"
44+
Environment = "${var.environment}"
45+
}
46+
}
47+
48+
/* Public subnet */
49+
resource "aws_subnet" "public_subnet" {
50+
vpc_id = "${aws_vpc.vpc.id}"
51+
count = "${length(var.public_subnets_cidr)}"
52+
cidr_block = "${element(var.public_subnets_cidr, count.index)}"
53+
availability_zone = "${element(var.availability_zones, count.index)}"
54+
map_public_ip_on_launch = true
55+
56+
tags = {
57+
Name = "${var.environment}-${element(var.availability_zones, count.index)}-public-subnet"
58+
Environment = "${var.environment}"
59+
}
60+
}
61+
62+
/* Private subnet */
63+
resource "aws_subnet" "private_subnet" {
64+
vpc_id = "${aws_vpc.vpc.id}"
65+
count = "${length(var.private_subnets_cidr)}"
66+
cidr_block = "${element(var.private_subnets_cidr, count.index)}"
67+
availability_zone = "${element(var.availability_zones, count.index)}"
68+
map_public_ip_on_launch = false
69+
70+
tags = {
71+
Name = "${var.environment}-${element(var.availability_zones, count.index)}-private-subnet"
72+
Environment = "${var.environment}"
73+
"kubernetes.io/role/elb" = "1"
74+
}
75+
}
76+
77+
/* Routing table for private subnet */
78+
resource "aws_route_table" "private" {
79+
vpc_id = "${aws_vpc.vpc.id}"
80+
81+
tags = {
82+
Name = "${var.environment}-private-route-table"
83+
Environment = "${var.environment}"
84+
}
85+
}
86+
87+
/* Routing table for public subnet */
88+
resource "aws_route_table" "public" {
89+
vpc_id = "${aws_vpc.vpc.id}"
90+
91+
tags = {
92+
Name = "${var.environment}-public-route-table"
93+
Environment = "${var.environment}"
94+
}
95+
}
96+
97+
resource "aws_route" "public_internet_gateway" {
98+
route_table_id = "${aws_route_table.public.id}"
99+
destination_cidr_block = "0.0.0.0/0"
100+
gateway_id = "${aws_internet_gateway.ig.id}"
101+
}
102+
103+
resource "aws_route" "private_nat_gateway" {
104+
route_table_id = "${aws_route_table.private.id}"
105+
destination_cidr_block = "0.0.0.0/0"
106+
nat_gateway_id = "${aws_nat_gateway.nat.id}"
107+
}
108+
109+
/* Route table associations */
110+
resource "aws_route_table_association" "public" {
111+
count = "${length(var.public_subnets_cidr)}"
112+
subnet_id = "${element(aws_subnet.public_subnet.*.id, count.index)}"
113+
route_table_id = "${aws_route_table.public.id}"
114+
}
115+
116+
resource "aws_route_table_association" "private" {
117+
count = "${length(var.private_subnets_cidr)}"
118+
subnet_id = "${element(aws_subnet.private_subnet.*.id, count.index)}"
119+
route_table_id = "${aws_route_table.private.id}"
120+
}
121+
122+
/*====
123+
VPC's Default Security Group
124+
======*/
125+
resource "aws_security_group" "default" {
126+
name = "${var.environment}-default-sg"
127+
description = "Default security group to allow inbound/outbound from the VPC"
128+
vpc_id = "${aws_vpc.vpc.id}"
129+
depends_on = [aws_vpc.vpc]
130+
131+
ingress {
132+
from_port = "0"
133+
to_port = "0"
134+
protocol = "-1"
135+
self = true
136+
}
137+
138+
egress {
139+
from_port = "0"
140+
to_port = "0"
141+
protocol = "-1"
142+
self = "true"
143+
}
144+
145+
tags = {
146+
Environment = "${var.environment}"
147+
}
148+
}
149+
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
output "vpc_id" {
2+
value = "${aws_vpc.vpc.id}"
3+
}
4+
5+
output "public_subnets_id" {
6+
value = ["${aws_subnet.public_subnet.*.id}"]
7+
}
8+
9+
output "private_subnets_id" {
10+
value = ["${aws_subnet.private_subnet.*.id}"]
11+
}
12+
13+
output "public_subnet_1" {
14+
value = "${aws_subnet.public_subnet.0.id}"
15+
}
16+
17+
output "public_subnet_2" {
18+
value = "${aws_subnet.public_subnet.1.id}"
19+
}
20+
21+
output "private_subnet_1" {
22+
value = "${aws_subnet.private_subnet.0.id}"
23+
}
24+
25+
output "private_subnet_2" {
26+
value = "${aws_subnet.private_subnet.1.id}"
27+
}
28+
29+
output "default_sg_id" {
30+
value = "${aws_security_group.default.id}"
31+
}
32+
33+
output "security_groups_ids" {
34+
value = ["${aws_security_group.default.id}"]
35+
}
36+
37+
output "public_route_table" {
38+
value = "${aws_route_table.public.id}"
39+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
variable "environment" {
2+
description = "The Deployment environment"
3+
}
4+
5+
variable "vpc_cidr" {
6+
description = "The CIDR block of the vpc"
7+
}
8+
9+
variable "public_subnets_cidr" {
10+
type = list
11+
description = "The CIDR block for the public subnet"
12+
}
13+
14+
variable "private_subnets_cidr" {
15+
type = list
16+
description = "The CIDR block for the private subnet"
17+
}
18+
19+
variable "region" {
20+
description = "The region to launch the bastion host"
21+
}
22+
23+
variable "availability_zones" {
24+
type = list
25+
description = "The az that the resources will be launched"
26+
}
27+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#tfvars
2+
3+
environment = "fargate"
4+
vpc_cidr = "10.0.0.0/16"
5+
region = "us-east-1"
6+
public_subnets_cidr = ["10.0.1.0/24", "10.0.2.0/24"]
7+
private_subnets_cidr = ["10.0.3.0/24", "10.0.4.0/24"]
8+
availability_zones = ["us-east-1a", "us-east-1b"]

0 commit comments

Comments
 (0)