Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test-env): add new environment named test in the deployment pipeline #329

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions .github/workflows/fta-migration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
32 changes: 25 additions & 7 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/api/ecs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/api/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/database/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/frontend/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(nit): If lower(var.target_env) is not a key in local.env_map, it will result in an error. I am wondering if we should do a lookup() first with a default fallback

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

imo it shouldn't default to any env and instead error out if it can't find it in the lookup table (env_map)

vpc_name = "${local.environment}_vpc"
availability_zones = ["a", "b"]
web_subnet_names = [for az in local.availability_zones : "Web_${local.environment}_az${az}_net"]
Expand Down
2 changes: 1 addition & 1 deletion infrastructure/migration/network.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down
24 changes: 24 additions & 0 deletions terraform/api/test/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -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
}
18 changes: 18 additions & 0 deletions terraform/database/test/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 20 additions & 0 deletions terraform/frontend/test/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -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
}
23 changes: 23 additions & 0 deletions terraform/migration/test/terragrunt.hcl
Original file line number Diff line number Diff line change
@@ -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
}
Loading