From 0a2bfb352215223f6a13c60a83ef5a50c06eae9d Mon Sep 17 00:00:00 2001 From: thomas loubrieu Date: Thu, 27 Jun 2024 16:15:55 -0400 Subject: [PATCH] add the load balancer to the terraform script --- terraform/ecs.tf | 40 ++++++++++++++++++++++++++++++++++++---- terraform/provider.tf | 2 -- terraform/variables.tf | 4 ++-- 3 files changed, 38 insertions(+), 8 deletions(-) diff --git a/terraform/ecs.tf b/terraform/ecs.tf index ffe65edf..0c729bde 100644 --- a/terraform/ecs.tf +++ b/terraform/ecs.tf @@ -36,7 +36,7 @@ resource "aws_ecs_service" "pds-registry-reg-service" { desired_count = 1 load_balancer { - target_group_arn = aws_lb_target_group.pds-registry-target-group.arn + target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn container_name = "pds-${var.venue}-reg-container" container_port = "80" } @@ -114,7 +114,29 @@ EOF } -resource "aws_lb_target_group" "pds-registry-target-group" { +resource "aws_lb" "registry-api-lb" { + name = "registry-api-lb-new" + internal = true + load_balancer_type = "application" + security_groups = var.aws_fg_security_groups + subnets = var.aws_fg_subnets + + enable_deletion_protection = true + + access_logs { + bucket = var.aws_s3_bucket_logs_id + prefix = "registry-api-lb" + enabled = true + } + + tags = { + Alfa = var.node_name_abbr + Bravo = var.venue + Charlie = "registry" + } +} + +resource "aws_lb_target_group" "pds-registry-api-target-group" { name = "pds-${var.venue}-registry-tgt" port = 80 protocol = "HTTP" @@ -129,12 +151,22 @@ resource "aws_lb_target_group" "pds-registry-target-group" { } } +resource "aws_lb_listener" "registry-api-ld-listener" { + load_balancer_arn = aws_lb.registry-api-lb.arn + port = 80 + protocol = "HTTP" + default_action { + type = "forward" + target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn + } +} + resource "aws_lb_listener_rule" "pds-registry-forward-rule" { - listener_arn = var.aws_lb_listener_arn + listener_arn = aws_lb_listener.registry-api-ld-listener.arn action { type = "forward" - target_group_arn = aws_lb_target_group.pds-registry-target-group.arn + target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn } # no condition for now diff --git a/terraform/provider.tf b/terraform/provider.tf index 09068174..00ce2170 100644 --- a/terraform/provider.tf +++ b/terraform/provider.tf @@ -14,7 +14,5 @@ terraform { # backend "s3" { bucket = "pds-infra" - # key = "project-services/${var.node_name_abbr}/${var.venue}/ecs.tfstate" - # region = var.aws_region } } diff --git a/terraform/variables.tf b/terraform/variables.tf index 97d87375..5d02b4f7 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -48,8 +48,8 @@ variable "aws_fg_image" { description = "AWS image name for Fargate" } -variable "aws_lb_listener_arn" { - description = "ARN of the AWS LB listener to associated with the service target group" +variable "aws_s3_bucket_logs_id" { + description = "AWS S3 bucket with the logs" } variable "aws_fg_cpu_units" {