Skip to content

Deploy Backend - preprod int-blue #65

Deploy Backend - preprod int-blue

Deploy Backend - preprod int-blue #65

name: Deploy Backend
on:
workflow_call:
inputs:
apigee_environment:
required: true
type: string
create_mns_subscription:
required: false
type: boolean
default: true
environment:
required: true
type: string
sub_environment:
required: true
type: string
workflow_dispatch:
inputs:
apigee_environment:
type: choice
description: Select the Apigee proxy environment
options:
- internal-dev
- internal-qa
- int
- ref
- prod
create_mns_subscription:
description: Create an MNS Subscription programatically. Only available in AWS dev
required: false
type: boolean
default: true
environment:
type: choice
description: Select the backend environment
options:
- dev
- preprod
- prod
sub_environment:
type: string
description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments
env: # Sonarcloud - do not allow direct usage of untrusted data
APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }}
ENVIRONMENT: ${{ inputs.environment }}
SUB_ENVIRONMENT: ${{ inputs.sub_environment }}
run-name: Deploy Backend - ${{ inputs.environment }} ${{ inputs.sub_environment }}
jobs:
terraform-plan:
permissions:
id-token: write
contents: read
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
- name: Connect to AWS
uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
with:
aws-region: eu-west-2
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
role-session-name: github-actions
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_version: "1.12.2"
- name: Terraform Init
working-directory: infrastructure/instance
run: make init
- name: Terraform Plan
working-directory: infrastructure/instance
run: make plan-ci
- name: Save Terraform Plan
uses: actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f
with:
name: ${{ env.ENVIRONMENT }}-${{ env.SUB_ENVIRONMENT }}-tfplan
path: infrastructure/instance/tfplan
terraform-apply:
permissions:
id-token: write
contents: read
needs: terraform-plan
runs-on: ubuntu-latest
environment:
name: ${{ inputs.environment }}
steps:
- name: Checkout
uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8
- uses: aws-actions/configure-aws-credentials@61815dcd50bd041e203e49132bacad1fd04d2708
with:
aws-region: eu-west-2
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
role-session-name: github-actions
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
with:
terraform_version: "1.12.2"
- name: Retrieve Terraform Plan
uses: actions/download-artifact@37930b1c2abaa49bbe596cd826c3c89aef350131
with:
name: ${{ env.ENVIRONMENT }}-${{ env.SUB_ENVIRONMENT }}-tfplan
path: infrastructure/instance
- name: Terraform Init
working-directory: infrastructure/instance
run: make init
- name: Terraform Apply
working-directory: infrastructure/instance
run: |
make apply-ci
echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV
- name: Install poetry
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
run: pip install poetry==2.1.4
- uses: actions/[email protected]
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
with:
python-version: 3.11
cache: "poetry"
cache-dependency-path: |
lambdas/mns_subscription/poetry.lock
lambdas/shared/poetry.lock
- name: Create MNS Subscription
if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }}
working-directory: "./lambdas/mns_subscription"
env:
APIGEE_ENVIRONMENT: int
SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }}
run: |
poetry install --no-root
echo "Subscribing SQS to MNS for notifications..."
make subscribe