Skip to content

Commit

Permalink
Wardship: update ecs, add logging using EventBridge (#3676)
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-k1998 authored Oct 16, 2023
1 parent f309cab commit fdbf5dd
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
35 changes: 28 additions & 7 deletions terraform/environments/wardship/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ resource "aws_ecs_cluster" "wardship_cluster" {
}
}

resource "aws_cloudwatch_log_group" "wardshipFamily_logs" {
name = "/ecs/wardshipFamily"
resource "aws_cloudwatch_log_group" "deployment_logs" {
name = "/aws/events/deploymentLogs"
}

resource "aws_ecs_task_definition" "wardship_task_definition" {
Expand All @@ -21,7 +21,7 @@ resource "aws_ecs_task_definition" "wardship_task_definition" {
container_definitions = jsonencode([
{
name = "wardship-container"
image = "mcr.microsoft.com/dotnet/framework/aspnet:4.8"
image = "${aws_ecr_repository.wardship_ecr_repo.repository_url}:latest"
cpu = 1024
memory = 2048
essential = true
Expand All @@ -35,7 +35,7 @@ resource "aws_ecs_task_definition" "wardship_task_definition" {
logConfiguration = {
logDriver = "awslogs"
options = {
awslogs-group = "${aws_cloudwatch_log_group.wardshipFamily_logs.name}"
awslogs-group = "${aws_cloudwatch_log_group.deployment_logs.name}"
awslogs-region = "eu-west-2"
awslogs-stream-prefix = "ecs"
}
Expand Down Expand Up @@ -96,8 +96,8 @@ resource "aws_ecs_service" "wardship_ecs_service" {
task_definition = aws_ecs_task_definition.wardship_task_definition.arn
launch_type = "FARGATE"
enable_execute_command = true
desired_count = 1
health_check_grace_period_seconds = 90
desired_count = 2
health_check_grace_period_seconds = 180

network_configuration {
subnets = data.aws_subnets.shared-public.ids
Expand Down Expand Up @@ -237,7 +237,28 @@ resource "aws_security_group" "ecs_service" {
}
}

resource "aws_ecr_repository" "wardship-ecr-repo" {
resource "aws_ecr_repository" "wardship_ecr_repo" {
name = "wardship-ecr-repo"
force_delete = true
}

# AWS EventBridge rule
resource "aws_cloudwatch_event_rule" "ecs_events" {
name = "ecs-events"
description = "Capture all ECS events"

event_pattern = jsonencode({
"source" : ["aws.ecs"],
"detail" : {
"clusterArn" : [aws_ecs_cluster.wardship_cluster.arn]
}
})
}

# AWS EventBridge target
resource "aws_cloudwatch_event_target" "logs" {
depends_on = [aws_cloudwatch_log_group.deployment_logs]
rule = aws_cloudwatch_event_rule.ecs_events.name
target_id = "send-to-cloudwatch"
arn = aws_cloudwatch_log_group.deployment_logs.arn
}
6 changes: 3 additions & 3 deletions terraform/environments/wardship/load_balancer.tf
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,12 @@ resource "aws_lb_target_group" "wardship_target_group" {

health_check {
healthy_threshold = "3"
interval = "15"
interval = "30"
protocol = "HTTP"
port = "80"
unhealthy_threshold = "3"
unhealthy_threshold = "5"
matcher = "200-302"
timeout = "5"
timeout = "10"
}

}
Expand Down

0 comments on commit fdbf5dd

Please sign in to comment.