From a1345ffebedef0f84ccafa2d2b3e0dbc5c33f7ca Mon Sep 17 00:00:00 2001 From: matt-k1998 Date: Fri, 13 Oct 2023 12:27:32 +0100 Subject: [PATCH] Wardship: Test ecs changes on dev --- terraform/environments/wardship/ecs.tf | 41 ++++++++++++------- .../environments/wardship/load_balancer.tf | 6 +-- 2 files changed, 30 insertions(+), 17 deletions(-) diff --git a/terraform/environments/wardship/ecs.tf b/terraform/environments/wardship/ecs.tf index 4e10002f119..83ad53fde42 100644 --- a/terraform/environments/wardship/ecs.tf +++ b/terraform/environments/wardship/ecs.tf @@ -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" { @@ -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 @@ -32,14 +32,6 @@ resource "aws_ecs_task_definition" "wardship_task_definition" { hostPort = 80 } ] - logConfiguration = { - logDriver = "awslogs" - options = { - awslogs-group = "${aws_cloudwatch_log_group.wardshipFamily_logs.name}" - awslogs-region = "eu-west-2" - awslogs-stream-prefix = "ecs" - } - } environment = [ { name = "RDS_HOSTNAME" @@ -96,8 +88,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 = 120 network_configuration { subnets = data.aws_subnets.shared-public.ids @@ -237,7 +229,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 +} \ No newline at end of file diff --git a/terraform/environments/wardship/load_balancer.tf b/terraform/environments/wardship/load_balancer.tf index 99c23ec0eac..0bf4dc66d52 100644 --- a/terraform/environments/wardship/load_balancer.tf +++ b/terraform/environments/wardship/load_balancer.tf @@ -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" } }