From 33e45136c0e158bae95ca8c1aa1b1478b114acbc Mon Sep 17 00:00:00 2001 From: Lucas Li <35748253+yzlucas@users.noreply.github.com> Date: Tue, 1 Oct 2024 14:56:59 -0700 Subject: [PATCH] Terraform 6 (#121) * changes * addding wfprev_db_subnet * update listener --- .github/workflows/terragrunt-deploy.yml | 2 +- terraform/alb.tf | 34 +++++++++++++++++++++++++ terraform/ecs.tf | 2 +- terraform/variables.tf | 21 ++++++++++++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/.github/workflows/terragrunt-deploy.yml b/.github/workflows/terragrunt-deploy.yml index 477cdaa58..69344fca8 100644 --- a/.github/workflows/terragrunt-deploy.yml +++ b/.github/workflows/terragrunt-deploy.yml @@ -127,7 +127,7 @@ jobs: WFPREV_API_PORT: ${{vars.WFPREV_API_PORT}} TARGET_AWS_ACCOUNT_ID: ${{secrets.TARGET_AWS_ACCOUNT_ID}} # WFPREV UI - CLIENT_IMAGE: ${{ vars.REPOSITORY }}/${{ github.repository }}-wfprev-ui:${{ inputs.IMAGE_TAG }} + CLIENT_IMAGE: ${{ vars.REPOSITORY }}/${{ github.repository }}-wfprev-war:${{ inputs.IMAGE_TAG }} WEBADE_OAUTH2_WFPREV_UI_CLIENT_SECRET: ${{ secrets.WEBADE_OAUTH2_WFPREV_UI_CLIENT_SECRET }} WFPREV_CLIENT_MEMORY: ${{vars.WFPREV_CLIENT_MEMORY}} WFPREV_CLIENT_CPU_UNITS : ${{vars.WFPREV_CLIENT_CPU_UNITS}} diff --git a/terraform/alb.tf b/terraform/alb.tf index c7d1aded6..a77d152f7 100644 --- a/terraform/alb.tf +++ b/terraform/alb.tf @@ -53,6 +53,40 @@ resource "aws_lb_listener" "wfprev_main" { } } +/// LISTENER RULES//// + +resource "aws_lb_listener_rule" "wfprev-api" { + listener_arn = aws_lb_listener.wfprev_main.arn + + action { + type = "forward" + target_group_arn = aws_alb_target_group.wfprev_api.arn + } + + condition { + path_pattern { + values = [for sn in var.PREVENTION_API_NAMES : "/${aws_apigatewayv2_stage.wfprev_stage.name}/${sn}"] + } + } +} + +resource "aws_lb_listener_rule" "wfprev-ui" { + listener_arn = aws_lb_listener.wfprev_main.arn + + action { + type = "forward" + target_group_arn = aws_alb_target_group.wfprev_ui.arn + } + + condition { + path_pattern { + values = [for sn in var.PREVENTION_WAR_NAMES : "/${aws_apigatewayv2_stage.wfprev_stage.name}/${sn}"] + } + } +} + + + ////////////////////////////// /// TARGET GROUP RESOURCES /// diff --git a/terraform/ecs.tf b/terraform/ecs.tf index 38ef55a4e..74feab392 100644 --- a/terraform/ecs.tf +++ b/terraform/ecs.tf @@ -44,7 +44,7 @@ resource "aws_ecs_task_definition" "wfprev_server" { essential = true readonlyRootFilesystem = true name = var.server_container_name - image = var.server_image + image = var.WFPREV_API_IMAGE repositoryCredentials = { credentialsParameter = aws_secretsmanager_secret.githubCredentials.arn } diff --git a/terraform/variables.tf b/terraform/variables.tf index 513286f9a..a5c012d8f 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -42,7 +42,13 @@ variable "CLIENT_IMAGE" { type = string default = "" } -variable "server_image" { +variable "SERVER_IMAGE" { + description = "Docker image to run in the ECS cluster. _Note_: there is a blank default value, which will cause service and task resource creation to be supressed unless an image is specified." + type = string + default = "" +} + +variable "WFPREV_API_IMAGE" { description = "Docker image to run in the ECS cluster. _Note_: there is a blank default value, which will cause service and task resource creation to be supressed unless an image is specified." type = string default = "" @@ -201,3 +207,16 @@ variable "DB_SIZE" { type = number default = 10 } + + +variable "PREVENTION_WAR_NAMES" { + type = list(string) + description = "List of paths to point at payroll API" + default = ["wfprev-ui", "wfprev-ui/*"] +} + +variable "PREVENTION_API_NAMES" { + type = list(string) + description = "List of paths to point at payroll API" + default = ["wfprev-api", "wfprev-api/*"] +} \ No newline at end of file