Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

availability of our app. autoscaling of front and back #86

Merged
merged 1 commit into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 86 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,23 @@ resource "aws_s3_bucket" "unibasement_images" {
bucket = "unibasement-images"
# TODO: remove for prod version
force_destroy = true
# TODO for prod version uncomment below.
# lifecycle {
# prevent_destroy = true
# }

tags = {
Name = "UniBasement Images"
}
}

resource "aws_s3_bucket_versioning" "unibasement_images" {
bucket = aws_s3_bucket.unibasement_images.id
versioning_configuration {
status = "Enabled"
}
}

resource "aws_s3_bucket_public_access_block" "unibasement_images" {
bucket = aws_s3_bucket.unibasement_images.id

Expand Down Expand Up @@ -162,6 +173,35 @@ resource "aws_ecs_service" "unibasement_frontend" {
}
}


# Autoscaling for frontend
resource "aws_appautoscaling_target" "unibasement_frontend" {
max_capacity = 1 #
min_capacity = 1
resource_id = "service/${aws_ecs_cluster.unibasement.name}/${aws_ecs_service.unibasement_frontend.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

resource "aws_appautoscaling_policy" "unibasement_frontend" {
name = "unibasement_frontend"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.unibasement_frontend.resource_id
scalable_dimension = aws_appautoscaling_target.unibasement_frontend.scalable_dimension
service_namespace = aws_appautoscaling_target.unibasement_frontend.service_namespace

target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageCPUUtilization"
}

target_value = 50.0
}
}




variable "auth0_domain" {
description = "Auth0 Domain"
}
Expand Down Expand Up @@ -413,6 +453,34 @@ resource "aws_ecs_task_definition" "unibasement_backend" {
DEFINITION
}


# Autoscaling for backend
resource "aws_appautoscaling_target" "unibasement_backend" {
max_capacity = 1
min_capacity = 1
resource_id = "service/${aws_ecs_cluster.unibasement.name}/${aws_ecs_service.unibasement_backend.name}"
scalable_dimension = "ecs:service:DesiredCount"
service_namespace = "ecs"
}

resource "aws_appautoscaling_policy" "unibasement_backend" {
name = "unibasement_backend"
policy_type = "TargetTrackingScaling"
resource_id = aws_appautoscaling_target.unibasement_backend.resource_id
scalable_dimension = aws_appautoscaling_target.unibasement_backend.scalable_dimension
service_namespace = aws_appautoscaling_target.unibasement_backend.service_namespace

target_tracking_scaling_policy_configuration {
predefined_metric_specification {
predefined_metric_type = "ECSServiceAverageCPUUtilization"
}

target_value = 50.0
}
}



resource "aws_security_group" "unibasement_backend" {
name = "unibasement_backend"
description = "unibasement Security Group"
Expand Down Expand Up @@ -512,6 +580,24 @@ resource "aws_lb_listener" "unibasement" {
}
}

data "aws_route53_zone" "unibasement" {
name = "g6.csse6400.xyz"
private_zone = false
}

resource "aws_route53_record" "unibasement" {
zone_id = data.aws_route53_zone.unibasement.zone_id
name = "g6"
type = "A"
alias {
name = aws_lb.unibasement.dns_name
zone_id = aws_lb.unibasement.zone_id
evaluate_target_health = true
}
}



resource "local_file" "url" {
content = "http://${aws_lb.unibasement.dns_name}:3000/"
filename = "./unibasement.txt"
Expand Down
Loading