|
| 1 | +name: Deploy Backend |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + apigee_environment: |
| 7 | + required: true |
| 8 | + type: string |
| 9 | + create_mns_subscription: |
| 10 | + required: false |
| 11 | + type: boolean |
| 12 | + default: true |
| 13 | + environment: |
| 14 | + required: true |
| 15 | + type: string |
| 16 | + sub_environment: |
| 17 | + required: true |
| 18 | + type: string |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + apigee_environment: |
| 22 | + type: choice |
| 23 | + description: Select the Apigee proxy environment |
| 24 | + options: |
| 25 | + - internal-dev |
| 26 | + - int |
| 27 | + - ref |
| 28 | + - prod |
| 29 | + create_mns_subscription: |
| 30 | + description: Create an MNS Subscription. Only available in dev |
| 31 | + required: false |
| 32 | + type: boolean |
| 33 | + default: true |
| 34 | + environment: |
| 35 | + type: string |
| 36 | + description: Select the backend environment |
| 37 | + options: |
| 38 | + - dev |
| 39 | + - preprod |
| 40 | + - prod |
| 41 | + sub_environment: |
| 42 | + type: string |
| 43 | + description: Set the sub environment name e.g. pr-xxx, or green/blue in higher environments |
| 44 | + |
| 45 | +jobs: |
| 46 | + terraform-plan: |
| 47 | + runs-on: ubuntu-latest |
| 48 | + environment: |
| 49 | + name: ${{ inputs.environment }} |
| 50 | + env: # Sonarcloud - do not allow direct usage of untrusted data |
| 51 | + APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }} |
| 52 | + BACKEND_ENVIRONMENT: ${{ inputs.environment }} |
| 53 | + BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }} |
| 54 | + permissions: |
| 55 | + id-token: write |
| 56 | + contents: read |
| 57 | + steps: |
| 58 | + - name: Connect to AWS |
| 59 | + uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a |
| 60 | + with: |
| 61 | + aws-region: eu-west-2 |
| 62 | + role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops |
| 63 | + role-session-name: github-actions |
| 64 | + |
| 65 | + - name: Whoami |
| 66 | + run: aws sts get-caller-identity |
| 67 | + |
| 68 | + - name: Checkout |
| 69 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 70 | + |
| 71 | + - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd |
| 72 | + with: |
| 73 | + terraform_version: "1.12.2" |
| 74 | + |
| 75 | + - name: Terraform Init |
| 76 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 77 | + run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 78 | + |
| 79 | + - name: Terraform Plan |
| 80 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 81 | + run: make plan apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 82 | + |
| 83 | + terraform-apply: |
| 84 | + needs: terraform-plan |
| 85 | + runs-on: ubuntu-latest |
| 86 | + environment: |
| 87 | + name: ${{ inputs.environment }} |
| 88 | + env: # Sonarcloud - do not allow direct usage of untrusted data |
| 89 | + APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }} |
| 90 | + BACKEND_ENVIRONMENT: ${{ inputs.environment }} |
| 91 | + BACKEND_SUB_ENVIRONMENT: ${{ inputs.sub_environment }} |
| 92 | + permissions: |
| 93 | + id-token: write |
| 94 | + contents: read |
| 95 | + steps: |
| 96 | + - name: Checkout |
| 97 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 98 | + |
| 99 | + - uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a |
| 100 | + with: |
| 101 | + aws-region: eu-west-2 |
| 102 | + role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops |
| 103 | + role-session-name: github-actions |
| 104 | + |
| 105 | + - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd |
| 106 | + with: |
| 107 | + terraform_version: "1.12.2" |
| 108 | + |
| 109 | + - name: Terraform Init |
| 110 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 111 | + run: make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 112 | + |
| 113 | + - name: Terraform Apply |
| 114 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 115 | + run: | |
| 116 | + make apply apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 117 | + echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV |
| 118 | +
|
| 119 | + - name: Install poetry |
| 120 | + if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }} |
| 121 | + run: pip install poetry==2.1.4 |
| 122 | + |
| 123 | + - uses: actions/setup-python@v5 |
| 124 | + if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }} |
| 125 | + with: |
| 126 | + python-version: 3.11 |
| 127 | + cache: 'poetry' |
| 128 | + |
| 129 | + - name: Create MNS Subscription |
| 130 | + if: ${{ inputs.environment == 'dev' && inputs.create_mns_subscription }} |
| 131 | + working-directory: './lambdas/mns_subscription' |
| 132 | + env: |
| 133 | + APIGEE_ENVIRONMENT: ${{ inputs.apigee_environment }} |
| 134 | + SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }} |
| 135 | + run: | |
| 136 | + poetry install --no-root |
| 137 | + echo "Subscribing SQS to MNS for notifications..." |
| 138 | + make subscribe |
0 commit comments