From f543dc2b53a7961922360dbe5b4b6fb22332bac8 Mon Sep 17 00:00:00 2001 From: jimmypalelil Date: Wed, 5 Feb 2025 10:11:16 -0800 Subject: [PATCH] chore(test-env): add new environment named test in the deployment pipeline --- .github/workflows/fta-migration.yml | 16 +++++++++---- .github/workflows/main.yml | 32 +++++++++++++++++++------ infrastructure/api/ecs.tf | 2 +- infrastructure/api/network.tf | 2 +- infrastructure/database/network.tf | 2 +- infrastructure/frontend/network.tf | 2 +- infrastructure/migration/network.tf | 2 +- terraform/api/test/terragrunt.hcl | 24 +++++++++++++++++++ terraform/database/test/terragrunt.hcl | 18 ++++++++++++++ terraform/frontend/test/terragrunt.hcl | 20 ++++++++++++++++ terraform/migration/test/terragrunt.hcl | 23 ++++++++++++++++++ 11 files changed, 127 insertions(+), 16 deletions(-) create mode 100644 terraform/api/test/terragrunt.hcl create mode 100644 terraform/database/test/terragrunt.hcl create mode 100644 terraform/frontend/test/terragrunt.hcl create mode 100644 terraform/migration/test/terragrunt.hcl diff --git a/.github/workflows/fta-migration.yml b/.github/workflows/fta-migration.yml index 2b737220..fe15c02b 100644 --- a/.github/workflows/fta-migration.yml +++ b/.github/workflows/fta-migration.yml @@ -5,6 +5,14 @@ on: # schedule: [cron: "0 3 * * *"] # Every day at 3 AM workflow_call: inputs: + app_env: + required: true + description: 'The APP env separates between AWS ENV and Actual APP, since AWS dev is where PR, and TEST is deployed' + type: string + environment_name: + description: 'The name of the environment to deploy to' + required: true + type: string tag: description: 'The tag of the containers to deploy' required: true @@ -17,14 +25,14 @@ permissions: pull-requests: write jobs: - run-fta-dev-migration: - name: Run FTA Dev Migration + run-fta-migration: + name: Run FTA ${{ inputs.app_env }} Migration uses: ./.github/workflows/.aws-deployer.yml with: - environment_name: dev + app_env: ${{ inputs.app_env || 'dev' }} + environment_name: ${{ inputs.environment_name || 'dev' }} command: apply flyway_image: ghcr.io/bcgov/nr-rec-resources/migrations/fta:${{ inputs.tag || 'latest' }} working_directory: migration tag: ${{ inputs.tag }} - app_env: dev secrets: inherit diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08a597ec..cf4ac9a2 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -53,11 +53,13 @@ jobs: secrets: inherit # Running FTA migration after each dev deployment since we are clearing the database each run - fta-migration: + fta-migration-dev: needs: deploy-to-aws-dev name: FTA Migration uses: ./.github/workflows/fta-migration.yml with: + app_env: dev + environment_name: dev tag: ${{ github.sha }} secrets: inherit @@ -71,14 +73,30 @@ jobs: - name: Review Test Deployment run: echo "Reviewing Test Deployment" + # Deploys to test environment in the same AWS account as dev. + # resources in test environment uses the same vpc as the dev (Dev_vpc) deploy-to-aws-test: name: Deploys Application to AWS test - needs: [review-test-deployment] - runs-on: ubuntu-24.04 - steps: - - name: Deploy to AWS test - # Placeholder - run: echo "Deploying to AWS test" + needs: [ review-test-deployment ] + uses: ./.github/workflows/.deploy-app.yml + with: + app_env: test + command: apply + environment_name: test + tag: ${{ github.sha }} + secrets: inherit + + # Running FTA migration after each dev deployment since we are clearing the database each run + fta-migration-test: + needs: deploy-to-aws-test + name: FTA Migration + uses: ./.github/workflows/fta-migration.yml + with: + app_env: test + environment_name: test + tag: ${{ github.sha }} + secrets: inherit + release: name: Release diff --git a/infrastructure/api/ecs.tf b/infrastructure/api/ecs.tf index 4ec7d543..43200ab7 100644 --- a/infrastructure/api/ecs.tf +++ b/infrastructure/api/ecs.tf @@ -82,7 +82,7 @@ module "flyway_task" { { # This defaults to true, though we want to enable it only in dev to reset the database name = "FLYWAY_CLEAN_DISABLED" - value = contains(["dev"], local.rds_app_env) ? "false" : "true" + value = contains(["dev", "test"], local.rds_app_env) ? "false" : "true" } ] aws_region = var.aws_region diff --git a/infrastructure/api/network.tf b/infrastructure/api/network.tf index 0c58d849..ba377403 100644 --- a/infrastructure/api/network.tf +++ b/infrastructure/api/network.tf @@ -6,7 +6,7 @@ locals { tools = "Tools" unclass = "UnClass" } - environment = local.env_map[lower(var.target_env)] + environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)] vpc_name = "${local.environment}_vpc" availability_zones = ["a", "b"] web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"] diff --git a/infrastructure/database/network.tf b/infrastructure/database/network.tf index 0c58d849..ba377403 100644 --- a/infrastructure/database/network.tf +++ b/infrastructure/database/network.tf @@ -6,7 +6,7 @@ locals { tools = "Tools" unclass = "UnClass" } - environment = local.env_map[lower(var.target_env)] + environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)] vpc_name = "${local.environment}_vpc" availability_zones = ["a", "b"] web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"] diff --git a/infrastructure/frontend/network.tf b/infrastructure/frontend/network.tf index 0c58d849..ba377403 100644 --- a/infrastructure/frontend/network.tf +++ b/infrastructure/frontend/network.tf @@ -6,7 +6,7 @@ locals { tools = "Tools" unclass = "UnClass" } - environment = local.env_map[lower(var.target_env)] + environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)] vpc_name = "${local.environment}_vpc" availability_zones = ["a", "b"] web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"] diff --git a/infrastructure/migration/network.tf b/infrastructure/migration/network.tf index 02a0d574..52abbd54 100644 --- a/infrastructure/migration/network.tf +++ b/infrastructure/migration/network.tf @@ -6,7 +6,7 @@ locals { tools = "Tools" unclass = "UnClass" } - environment = local.env_map[lower(var.target_env)] + environment = local.env_map[lower(var.target_env) == "test" ? "dev" : lower(var.target_env)] vpc_name = "${local.environment}_vpc" availability_zones = ["a", "b"] app_subnet_names = [for az in local.availability_zones : "App_${local.environment}_az${az}_net"] diff --git a/terraform/api/test/terragrunt.hcl b/terraform/api/test/terragrunt.hcl new file mode 100644 index 00000000..b6f74965 --- /dev/null +++ b/terraform/api/test/terragrunt.hcl @@ -0,0 +1,24 @@ +include { + path = find_in_parent_folders() +} +locals { + app_env = get_env("app_env") + flyway_image = get_env("flyway_image") + api_image = get_env("api_image") + target_env = get_env("target_env") + +} + +# Include the common terragrunt configuration for all modules +generate "test_tfvars" { + path = "test.auto.tfvars" + if_exists = "overwrite" + disable_signature = true + contents = <<-EOF + target_env = "test" + flyway_image="${local.flyway_image}" + api_image="${local.api_image}" + app_env="${local.app_env}" + app_name="node-api-${local.app_env}" +EOF +} diff --git a/terraform/database/test/terragrunt.hcl b/terraform/database/test/terragrunt.hcl new file mode 100644 index 00000000..338d8ebc --- /dev/null +++ b/terraform/database/test/terragrunt.hcl @@ -0,0 +1,18 @@ +include { + path = find_in_parent_folders() +} +locals { + app_env = get_env("app_env") +} + +# Include the common terragrunt configuration for all modules +generate "test_tfvars" { + path = "test.auto.tfvars" + if_exists = "overwrite" + disable_signature = true + contents = <<-EOF + target_env = "test" + db_cluster_name = "qsawsc-aurora-cluster-${local.app_env}" + app_env="${local.app_env}" +EOF +} diff --git a/terraform/frontend/test/terragrunt.hcl b/terraform/frontend/test/terragrunt.hcl new file mode 100644 index 00000000..19bff758 --- /dev/null +++ b/terraform/frontend/test/terragrunt.hcl @@ -0,0 +1,20 @@ +include { + path = find_in_parent_folders() +} +locals { + app_env = get_env("app_env") + target_env = get_env("target_env") + +} + +# Include the common terragrunt configuration for all modules +generate "test_tfvars" { + path = "test.auto.tfvars" + if_exists = "overwrite" + disable_signature = true + contents = <<-EOF + target_env = "test" + app_env="${local.app_env}" + app_name="frontend-${local.app_env}" +EOF +} diff --git a/terraform/migration/test/terragrunt.hcl b/terraform/migration/test/terragrunt.hcl new file mode 100644 index 00000000..f515217d --- /dev/null +++ b/terraform/migration/test/terragrunt.hcl @@ -0,0 +1,23 @@ +include { + path = find_in_parent_folders() +} +locals { + app_env = get_env("app_env") + flyway_image = get_env("flyway_image") + api_image = get_env("api_image") + target_env = get_env("target_env") +} + +# Include the common terragrunt configuration for all modules +generate "test_tfvars" { + path = "test.auto.tfvars" + if_exists = "overwrite" + disable_signature = true + contents = <<-EOF + target_env = "test" + flyway_image="${local.flyway_image}" + api_image="${local.api_image}" + app_env="${local.app_env}" + app_name="node-api-${local.app_env}" +EOF +}