Skip to content

Commit

Permalink
fix terraform deployment on MCP dev
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas loubrieu committed Aug 1, 2024
1 parent c9408ff commit 3cd707f
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 80 deletions.
2 changes: 2 additions & 0 deletions service/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ debug=true
logging.level.root = DEBUG
log4j.logger.org.springframework=DEBUG
logging.level.gov.nasa.pds.api.registry.opensearch = DEBUG
logging.level.org.apache.hc.client5.http.wire = INFO
logging.level.org.apache.http.wire = INFO

server.ssl.enabled=false
server.ssl.key-alias=registry
Expand Down
163 changes: 83 additions & 80 deletions terraform/ecs.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,68 @@
resource "aws_lb" "registry-api-lb" {
name = "registry-api-lb-new"
internal = false
load_balancer_type = "application"
security_groups = var.aws_fg_security_groups
subnets = var.aws_lb_subnets

enable_deletion_protection = false

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"
target_type = "ip"
vpc_id = var.aws_fg_vpc

health_check {
enabled = true
path = "/healthcheck"
matcher = "200"
interval = 300
}
}

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 = aws_lb_listener.registry-api-ld-listener.arn

action {
type = "forward"
target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn
}

# no condition for now
# TODO add condition so that the same load balancer can be
# used for multiple back-end service
condition {
path_pattern {
values = ["/*"]
}
}
}

# Define the cluster
resource "aws_ecs_cluster" "pds-registry-api-ecs" {
name = "pds-${var.venue}-registry-api-ecs"
Expand Down Expand Up @@ -26,33 +91,6 @@ resource "aws_cloudwatch_log_group" "pds-registry-log-group" {
}
}

# The main service.
resource "aws_ecs_service" "pds-registry-reg-service" {
name = "pds-${var.venue}-registry-api-service"
task_definition = aws_ecs_task_definition.pds-registry-ecs-task.arn
cluster = aws_ecs_cluster.pds-registry-api-ecs.id
launch_type = "FARGATE"

desired_count = 1

load_balancer {
target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn
container_name = "pds-${var.venue}-reg-container"
container_port = "80"
}

network_configuration {
assign_public_ip = false
security_groups = var.aws_fg_security_groups
subnets = var.aws_fg_subnets
}

tags = {
Alfa = var.node_name_abbr
Bravo = var.venue
Charlie = "registry"
}
}

# The task definition for app.
resource "aws_ecs_task_definition" "pds-registry-ecs-task" {
Expand Down Expand Up @@ -114,19 +152,26 @@ EOF
}


resource "aws_lb" "registry-api-lb" {
name = "registry-api-lb-new"
internal = false
load_balancer_type = "application"
security_groups = var.aws_fg_security_groups
subnets = var.aws_fg_subnets

enable_deletion_protection = false
# The main service.
resource "aws_ecs_service" "pds-registry-reg-service" {
name = "pds-${var.venue}-registry-api-service"
task_definition = aws_ecs_task_definition.pds-registry-ecs-task.arn
cluster = aws_ecs_cluster.pds-registry-api-ecs.id
launch_type = "FARGATE"

access_logs {
bucket = var.aws_s3_bucket_logs_id
prefix = "registry-api-lb"
enabled = true
desired_count = 1

load_balancer {
target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn
container_name = "pds-${var.venue}-reg-container"
container_port = "80"
}

network_configuration {
assign_public_ip = false
security_groups = var.aws_fg_security_groups
subnets = var.aws_fg_subnets
}

tags = {
Expand All @@ -136,45 +181,3 @@ resource "aws_lb" "registry-api-lb" {
}
}

resource "aws_lb_target_group" "pds-registry-api-target-group" {
name = "pds-${var.venue}-registry-tgt"
port = 80
protocol = "HTTP"
target_type = "ip"
vpc_id = var.aws_fg_vpc

health_check {
enabled = true
path = "/healthcheck"
matcher = "200"
interval = 300
}
}

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 = aws_lb_listener.registry-api-ld-listener.arn

action {
type = "forward"
target_group_arn = aws_lb_target_group.pds-registry-api-target-group.arn
}

# no condition for now
# TODO add condition so that the same load balancer can be
# used for multiple back-end service
condition {
path_pattern {
values = ["/*"]
}
}
}
5 changes: 5 additions & 0 deletions terraform/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ variable "aws_fg_subnets" {
type = list(string)
}

variable "aws_lb_subnets" {
description = "AWS Subnets for the load balancer"
type = list(string)
}

variable "ecs_task_role" {
description = "ECS task role"
}
Expand Down

0 comments on commit 3cd707f

Please sign in to comment.