diff --git a/terraform/environments/ncas/ecs.tf b/terraform/environments/ncas/ecs.tf index 636d512c066..2e498145b32 100644 --- a/terraform/environments/ncas/ecs.tf +++ b/terraform/environments/ncas/ecs.tf @@ -6,8 +6,8 @@ resource "aws_ecs_cluster" "ncas_cluster" { } } -resource "aws_cloudwatch_log_group" "ncasFamily_logs" { - name = "/ecs/ncasFamily" +resource "aws_cloudwatch_log_group" "deployment_logs" { + name = "/aws/events/deploymentLogs" } resource "aws_ecs_task_definition" "ncas_task_definition" { @@ -21,7 +21,7 @@ resource "aws_ecs_task_definition" "ncas_task_definition" { container_definitions = jsonencode([ { name = "ncas-container" - image = "mcr.microsoft.com/dotnet/framework/aspnet:4.8" + image = "${aws_ecr_repository.ncas_ecr_repo.repository_url}:latest" cpu = 1024 memory = 2048 essential = true @@ -35,7 +35,7 @@ resource "aws_ecs_task_definition" "ncas_task_definition" { logConfiguration = { logDriver = "awslogs" options = { - awslogs-group = "${aws_cloudwatch_log_group.ncasFamily_logs.name}" + awslogs-group = "${aws_cloudwatch_log_group.deployment_logs.name}" awslogs-region = "eu-west-2" awslogs-stream-prefix = "ecs" } @@ -92,8 +92,8 @@ resource "aws_ecs_service" "ncas_ecs_service" { task_definition = aws_ecs_task_definition.ncas_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 @@ -239,3 +239,24 @@ resource "aws_ecr_repository" "ncas_ecr_repo" { name = "ncas-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.ncas_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 +} diff --git a/terraform/environments/ncas/load_balancer.tf b/terraform/environments/ncas/load_balancer.tf index 9d35f58e64c..52afb7197e1 100644 --- a/terraform/environments/ncas/load_balancer.tf +++ b/terraform/environments/ncas/load_balancer.tf @@ -131,12 +131,12 @@ resource "aws_lb_target_group" "ncas_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" } }