Skip to content

Commit

Permalink
add the load balancer to the terraform script
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas loubrieu committed Jun 27, 2024
1 parent 4c5d706 commit 0a2bfb3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 8 deletions.
40 changes: 36 additions & 4 deletions terraform/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
Expand All @@ -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
Expand Down
2 changes: 0 additions & 2 deletions terraform/provider.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down

0 comments on commit 0a2bfb3

Please sign in to comment.