Skip to content

Commit e66e609

Browse files
Initial commit
1 parent 225530a commit e66e609

File tree

8 files changed

+275
-40
lines changed

8 files changed

+275
-40
lines changed

.csse6400/bin/clean_repository.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#
3+
# Ensure that students have not committed inappropriate files for a Git repository.
4+
5+
# The following files are not allowed in a Git repository.
6+
ILLEGAL_FILES=(.DS_Store .localized .DS_Store? ._* .Spotlight-V100 .Trashes Thumbs.db ehthumbs.db desktop.ini)
7+
ILLEGAL_FILES+=(*.pyc *.pyo *.exe *.dll *.so *.a *.o *.obj *.lib)
8+
ILLEGAL_FILES+=(__pycache__ *.class *.jar *.war *.rar)
9+
ILLEGAL_FILES+=(*.sqlite *.sqlite3 *.sqlite-journal *.db *.db-journal)
10+
ILLEGAL_FILES+=(credentials .terraform)
11+
12+
failed=0
13+
for file in "${ILLEGAL_FILES[@]}"; do
14+
matches=$(git ls-files "${file}" 2>/dev/null)
15+
if [[ -n "${matches}" ]]; then
16+
echo "Found illegal file: ${matches}"
17+
failed=1
18+
fi
19+
done
20+
21+
if [ $failed -eq 1 ]; then
22+
echo "FAIL: Found illegal files in repository."
23+
echo "These files should not be committed to Git repositories - it is a good practice to add them to a .gitignore file."
24+
echo "Please remove these files and try again."
25+
exit 1
26+
fi
27+
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#!/bin/bash
2+
#
3+
# Validate that the repository has the following structure:
4+
# -- README.md
5+
# -- main.tf
6+
# -- db.tf
7+
# -- ecs.tf
8+
# -- autoscaling.tf
9+
# -- lb.tf
10+
# -- k6.js
11+
#
12+
13+
failed=0
14+
for file in README.md main.tf db.tf ecs.tf autoscaling.tf lb.tf k6.js; do
15+
if [ ! -f "$file" ]; then
16+
echo "FAIL: Missing $file"
17+
failed=1
18+
fi
19+
done
20+
21+
if [ $failed -eq 1 ]; then
22+
echo "Repository structure is not valid. Please fix the errors above."
23+
exit 1
24+
fi
25+

.github/workflows/classroom.yml

Lines changed: 0 additions & 40 deletions
This file was deleted.

.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# AWS credentials file
2+
credentials
3+
4+
# Default Terrform .gitignore
5+
# Local .terraform directories
6+
**/.terraform/*
7+
8+
# .tfstate files
9+
*.tfstate
10+
*.tfstate.*
11+
12+
# Crash log files
13+
crash.log
14+
crash.*.log
15+
16+
# Exclude all .tfvars files, which are likely to contain sensitive data, such as
17+
# password, private keys, and other secrets. These should not be part of version
18+
# control as they are data points which are potentially sensitive and subject
19+
# to change depending on the environment.
20+
*.tfvars
21+
*.tfvars.json
22+
23+
# Ignore override files as they are usually used to override resources locally and so
24+
# are not checked in
25+
override.tf
26+
override.tf.json
27+
*_override.tf
28+
*_override.tf.json
29+
30+
# Include override files you do wish to add to version control using negated pattern
31+
# !example_override.tf
32+
33+
# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
34+
# example: *tfplan*
35+
36+
# Ignore CLI configuration files
37+
.terraformrc
38+
terraform.rc
39+
40+
# Ignore Apple .DS_store files
41+
**/.DS_Store

README.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# CSSE6400 Week 6 Practical
2+
3+
Deploying our TaskOverflow application to ECS with a load balancer on AWS using Terraform.
4+
5+
Please see the [instructions](https://csse6400.uqcloud.net/practicals/week06.pdf) for more details.
6+
7+
Update this README file with appropriate information about your project, including how to run it.
8+
9+
There are [resources](https://www.makeareadme.com) available to help you write a good README file.

db.tf

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
resource "aws_db_instance" "taskoverflow_database" {
2+
allocated_storage = 20
3+
max_allocated_storage = 1000
4+
engine = "postgres"
5+
engine_version = "14"
6+
instance_class = "db.t4g.micro"
7+
db_name = "taskoverflow"
8+
username = local.database_username
9+
password = local.database_password
10+
parameter_group_name = "default.postgres14"
11+
skip_final_snapshot = true
12+
vpc_security_group_ids = [aws_security_group.taskoverflow_database.id]
13+
publicly_accessible = true
14+
tags = {
15+
Name = "taskoverflow_database"
16+
}
17+
}
18+
19+
resource "aws_security_group" "taskoverflow_database" {
20+
name = "taskoverflow_database"
21+
description = "Allow inbound Postgres traffic"
22+
23+
ingress {
24+
from_port = 5432
25+
to_port = 5432
26+
protocol = "tcp"
27+
cidr_blocks = ["0.0.0.0/0"]
28+
}
29+
30+
egress {
31+
from_port = 0
32+
to_port = 0
33+
protocol = "-1"
34+
cidr_blocks = ["0.0.0.0/0"]
35+
ipv6_cidr_blocks = ["::/0"]
36+
}
37+
38+
tags = {
39+
Name = "taskoverflow_db_security_group"
40+
}
41+
}

ecs.tf

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
resource "aws_ecs_cluster" "taskoverflow" {
2+
name = "taskoverflow"
3+
}
4+
5+
resource "aws_ecs_task_definition" "taskoverflow" {
6+
family = "taskoverflow"
7+
network_mode = "awsvpc"
8+
requires_compatibilities = ["FARGATE"]
9+
cpu = 1024
10+
memory = 2048
11+
execution_role_arn = data.aws_iam_role.lab.arn
12+
13+
container_definitions = <<DEFINITION
14+
[
15+
{
16+
"image": "${local.image}",
17+
"cpu": 1024,
18+
"memory": 2048,
19+
"name": "taskoverflow",
20+
"networkMode": "awsvpc",
21+
"portMappings": [
22+
{
23+
"containerPort": 6400,
24+
"hostPort": 6400
25+
}
26+
],
27+
"environment": [
28+
{
29+
"name": "SQLALCHEMY_DATABASE_URI",
30+
"value": "postgresql://${local.database_username}:${local.database_password}@${aws_db_instance.taskoverflow_database.address}:${aws_db_instance.taskoverflow_database.port}/${aws_db_instance.taskoverflow_database.db_name}"
31+
}
32+
],
33+
"logConfiguration": {
34+
"logDriver": "awslogs",
35+
"options": {
36+
"awslogs-group": "/taskoverflow/db",
37+
"awslogs-region": "us-east-1",
38+
"awslogs-stream-prefix": "ecs",
39+
"awslogs-create-group": "true"
40+
}
41+
}
42+
}
43+
]
44+
DEFINITION
45+
}
46+
47+
resource "aws_ecs_service" "taskoverflow" {
48+
name = "taskoverflow"
49+
cluster = aws_ecs_cluster.taskoverflow.id
50+
task_definition = aws_ecs_task_definition.taskoverflow.arn
51+
desired_count = 1
52+
launch_type = "FARGATE"
53+
54+
network_configuration {
55+
subnets = data.aws_subnets.private.ids
56+
security_groups = [aws_security_group.taskoverflow.id]
57+
assign_public_ip = true
58+
}
59+
60+
}
61+
62+
resource "aws_security_group" "taskoverflow" {
63+
name = "taskoverflow"
64+
description = "TaskOverflow Security Group"
65+
66+
ingress {
67+
from_port = 6400
68+
to_port = 6400
69+
protocol = "tcp"
70+
cidr_blocks = ["0.0.0.0/0"]
71+
}
72+
73+
ingress {
74+
from_port = 22
75+
to_port = 22
76+
protocol = "tcp"
77+
cidr_blocks = ["0.0.0.0/0"]
78+
}
79+
80+
egress {
81+
from_port = 0
82+
to_port = 0
83+
protocol = "-1"
84+
cidr_blocks = ["0.0.0.0/0"]
85+
}
86+
87+
tags = {
88+
Name = "taskoverflow_security_group"
89+
}
90+
}

main.tf

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
terraform {
2+
required_providers {
3+
aws = {
4+
source = "hashicorp/aws"
5+
version = "~> 5.0"
6+
}
7+
}
8+
}
9+
10+
provider "aws" {
11+
region = "us-east-1"
12+
shared_credentials_files = ["./credentials"]
13+
default_tags {
14+
tags = {
15+
Course = "CSSE6400"
16+
Name = "TaskOverflow"
17+
Automation = "Terraform"
18+
}
19+
}
20+
}
21+
22+
locals {
23+
image = "ghcr.io/csse6400/taskoverflow:latest"
24+
database_username = "administrator"
25+
database_password = "VerySecurePassword123XYZ"
26+
}
27+
28+
data "aws_iam_role" "lab" {
29+
name = "LabRole"
30+
}
31+
32+
data "aws_vpc" "default" {
33+
default = true
34+
}
35+
36+
data "aws_subnets" "private" {
37+
filter {
38+
name = "vpc-id"
39+
values = [data.aws_vpc.default.id]
40+
}
41+
}
42+

0 commit comments

Comments
 (0)