From 138df65087c5ab4bfe45b4714fbf02f14a5077e0 Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 11:46:28 -0500 Subject: [PATCH 1/9] modified to add demo as a workspace --- .github/workflows/terraform_plan.yaml | 2 +- terraform/implementation/ecs/demo.tfvars | 3 +++ terraform/implementation/ecs/main.tf | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 terraform/implementation/ecs/demo.tfvars diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 27a95ac4..8c9e9a3b 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -19,7 +19,7 @@ permissions: contents: read env: - workspace: dev + workspace: ${{ github.event.inputs.workspace }} jobs: terraform: diff --git a/terraform/implementation/ecs/demo.tfvars b/terraform/implementation/ecs/demo.tfvars new file mode 100644 index 00000000..14163b6f --- /dev/null +++ b/terraform/implementation/ecs/demo.tfvars @@ -0,0 +1,3 @@ +owner = "skylight" +project = "qc" +region = "us-east-1" \ No newline at end of file diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index a4944302..b666fed3 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -136,7 +136,7 @@ module "ecs" { resource "aws_db_instance" "qc_db" { allocated_storage = "10" - db_name = var.qc_db_name + db_name = "var.qc_db_name-${terraform.workspace}" identifier = var.db_identifier engine = var.db_engine_type engine_version = var.db_engine_version From 05c2217d5369c3c78f73abbd059ac242244eb3f3 Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 14:10:58 -0500 Subject: [PATCH 2/9] added terraform apply cert, testing trigger, added workspace to db subnet group --- .github/workflows/terraform_plan.yaml | 9 +++++++++ terraform/implementation/ecs/main.tf | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 8c9e9a3b..a9ab1a64 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -2,6 +2,9 @@ name: Ad-hoc Terraform Plan run-name: Terraform plan ${{ inputs.workspace }} by @${{ github.actor }} on: + pull_request: + branches: + - shanice/change_app_url workflow_dispatch: inputs: workspace: @@ -68,6 +71,12 @@ jobs: -backend-config "region=$REGION" \ || (echo "terraform init failed, exiting..." && exit 1) terraform workspace select "$WORKSPACE" + terraform apply -auto-approve -target=aws_acm_certificate.cloudflare_cert \ + -var-file="$WORKSPACE.tfvars" \ + -var "umls_api_key=${UMLS_API_KEY}" \ + -var "ersd_api_key=${ERSD_API_KEY}" \ + -var "qc_tls_key=${TLS_KEY}" \ + -var "qc_tls_cert=${TLS_CERT}" terraform plan \ -var-file="$WORKSPACE.tfvars" \ -var "umls_api_key=${UMLS_API_KEY}" \ diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index b666fed3..0eda4a60 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -152,7 +152,7 @@ resource "aws_db_instance" "qc_db" { # Create a DB subnet group resource "aws_db_subnet_group" "this" { - name = "${var.db_identifier}-subnet-group" + name = "${var.db_identifier}-subnet-group-${terraform.workspace}" subnet_ids = module.vpc.private_subnets } From 073e202001f574d463c18cb190d862bd3f8ef20b Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 15:06:06 -0500 Subject: [PATCH 3/9] modified terraform full workflow to grab terraform workspace dynamically from input --- .github/workflows/ecs_terraform.yaml | 2 +- .github/workflows/terraform_plan.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ecs_terraform.yaml b/.github/workflows/ecs_terraform.yaml index df60ab9b..dc7aa53a 100644 --- a/.github/workflows/ecs_terraform.yaml +++ b/.github/workflows/ecs_terraform.yaml @@ -25,7 +25,7 @@ permissions: contents: read env: - workspace: dev + workspace: ${{ github.event.inputs.workspace }} jobs: terraform: diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index a9ab1a64..52c7c0b4 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -4,7 +4,7 @@ run-name: Terraform plan ${{ inputs.workspace }} by @${{ github.actor }} on: pull_request: branches: - - shanice/change_app_url + - shanice/deploy_demo_ecs workflow_dispatch: inputs: workspace: From d71f07407bbdecbec200a4216675c771ba1a4cdb Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 16:59:22 -0500 Subject: [PATCH 4/9] made db parameter group more unique --- terraform/implementation/ecs/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index 0eda4a60..a5b9eb3d 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -159,7 +159,7 @@ resource "aws_db_subnet_group" "this" { # Create a parameter group to configure Postgres RDS parameters resource "aws_db_parameter_group" "this" { - name = "${var.db_identifier}-pg" + name = "${var.db_identifier}-pg-${terraform.workspace}" family = var.db_family parameter { From aeb6326a166a415b886d21700d674e47c9e4fd75 Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 17:21:52 -0500 Subject: [PATCH 5/9] fixed db name to add workspace --- terraform/implementation/ecs/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index a5b9eb3d..5958d0d8 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -136,7 +136,7 @@ module "ecs" { resource "aws_db_instance" "qc_db" { allocated_storage = "10" - db_name = "var.qc_db_name-${terraform.workspace}" + db_name = "${var.qc_db_name}-${terraform.workspace}" identifier = var.db_identifier engine = var.db_engine_type engine_version = var.db_engine_version From 573043ef693f39dfbac74e4a2afacd5822863eee Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 17:30:33 -0500 Subject: [PATCH 6/9] added workspace to db identifier --- terraform/implementation/ecs/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index 5958d0d8..18e554ab 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -137,7 +137,7 @@ module "ecs" { resource "aws_db_instance" "qc_db" { allocated_storage = "10" db_name = "${var.qc_db_name}-${terraform.workspace}" - identifier = var.db_identifier + identifier = "${var.db_identifier}-${terraform.workspace}" engine = var.db_engine_type engine_version = var.db_engine_version enabled_cloudwatch_logs_exports = ["postgresql", "upgrade"] From 701f189d039524f4eef9930ccd1874208c89773e Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 17:39:28 -0500 Subject: [PATCH 7/9] fixed DBName must begin with a letter and contain only alphanumeric characters error --- terraform/implementation/ecs/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/terraform/implementation/ecs/main.tf b/terraform/implementation/ecs/main.tf index 18e554ab..0c993db8 100644 --- a/terraform/implementation/ecs/main.tf +++ b/terraform/implementation/ecs/main.tf @@ -136,7 +136,7 @@ module "ecs" { resource "aws_db_instance" "qc_db" { allocated_storage = "10" - db_name = "${var.qc_db_name}-${terraform.workspace}" + db_name = "${var.qc_db_name}_${terraform.workspace}" identifier = "${var.db_identifier}-${terraform.workspace}" engine = var.db_engine_type engine_version = var.db_engine_version From c8f384566b2a24f763f754c9c7b6f7bec426715b Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 22:09:13 -0500 Subject: [PATCH 8/9] removed push on main from Terraform Plan & Terraform Apply, removed testing code from Ad-hoc Terraform Plan --- .github/workflows/ecs_terraform.yaml | 12 ++++++------ .github/workflows/terraform_plan.yaml | 17 ++++++++++------- 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/.github/workflows/ecs_terraform.yaml b/.github/workflows/ecs_terraform.yaml index dc7aa53a..604fcece 100644 --- a/.github/workflows/ecs_terraform.yaml +++ b/.github/workflows/ecs_terraform.yaml @@ -5,16 +5,16 @@ on: merge_group: types: - checks_requested - push: - branches: - - main workflow_dispatch: inputs: workspace: - description: "The workspace to terraform against" + description: "Choose terraform workspace for deployment" required: true - type: string - default: "dev" + type: choice + options: + - dev + - demo + default: dev concurrency: group: ${{ github.event.inputs.workspace }}-terraform diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index 52c7c0b4..a2ecce6f 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -2,16 +2,19 @@ name: Ad-hoc Terraform Plan run-name: Terraform plan ${{ inputs.workspace }} by @${{ github.actor }} on: - pull_request: - branches: - - shanice/deploy_demo_ecs + merge_group: + types: + - checks_requested workflow_dispatch: inputs: workspace: - description: "The workspace to terraform against" + description: "Choose terraform workspace for deployment" required: true - type: string - default: "dev" + type: choice + options: + - dev + - demo + default: dev concurrency: group: ${{ github.event.inputs.workspace }}-terraform @@ -52,7 +55,6 @@ jobs: - name: Terraform env: - # ACTION: ${{ env.terraform_action }} BUCKET: ${{ secrets.TFSTATE_BUCKET }} DYNAMODB_TABLE: ${{ secrets.TFSTATE_DYNAMODB_TABLE }} REGION: ${{ vars.region }} @@ -63,6 +65,7 @@ jobs: TLS_KEY: ${{ secrets.TLS_KEY}} shell: bash run: | + echo "Deploying to ${{ github.event.inputs.workspace }}..." rm -rf .terraform .terraform.lock.hcl terraform init \ -var-file="$WORKSPACE.tfvars" \ From 275215fc8bbc505240431bddb7cdcdc760706b0b Mon Sep 17 00:00:00 2001 From: shanice-skylight Date: Thu, 9 Jan 2025 22:12:40 -0500 Subject: [PATCH 9/9] added test code --- .github/workflows/terraform_plan.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/terraform_plan.yaml b/.github/workflows/terraform_plan.yaml index a2ecce6f..187c6f2c 100644 --- a/.github/workflows/terraform_plan.yaml +++ b/.github/workflows/terraform_plan.yaml @@ -2,6 +2,9 @@ name: Ad-hoc Terraform Plan run-name: Terraform plan ${{ inputs.workspace }} by @${{ github.actor }} on: + pull_request: + branches: + - shanice/deploy_demo_ecs merge_group: types: - checks_requested