|
| 1 | +name: PR Teardown |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + types: [closed] |
| 6 | + workflow_dispatch: |
| 7 | + inputs: |
| 8 | + pr_number: |
| 9 | + description: The PR number of the environment to teardown e.g 123 |
| 10 | + required: true |
| 11 | + type: string |
| 12 | + |
| 13 | +jobs: |
| 14 | + teardown: |
| 15 | + name: PR Teardown |
| 16 | + runs-on: ubuntu-latest |
| 17 | + environment: |
| 18 | + name: dev |
| 19 | + env: |
| 20 | + APIGEE_ENVIRONMENT: internal-dev |
| 21 | + BACKEND_ENVIRONMENT: dev |
| 22 | + BACKEND_SUB_ENVIRONMENT: pr-${{ github.event_name == 'pull_request' && github.event.pull_request.number || inputs.pr_number }} |
| 23 | + permissions: |
| 24 | + id-token: write |
| 25 | + contents: read |
| 26 | + |
| 27 | + steps: |
| 28 | + - name: Connect to AWS |
| 29 | + uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a |
| 30 | + with: |
| 31 | + aws-region: eu-west-2 |
| 32 | + role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops |
| 33 | + role-session-name: github-actions |
| 34 | + |
| 35 | + - name: Whoami |
| 36 | + run: aws sts get-caller-identity |
| 37 | + |
| 38 | + - name: Checkout |
| 39 | + uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 |
| 40 | + |
| 41 | + - uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd |
| 42 | + with: |
| 43 | + terraform_version: "1.12.2" |
| 44 | + |
| 45 | + - name: Terraform Init and extract MNS SQS QUEUE ARN |
| 46 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 47 | + run: | |
| 48 | + make init apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 49 | + make workspace apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
| 50 | + echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV |
| 51 | +
|
| 52 | + - name: Install poetry |
| 53 | + run: pip install poetry==2.1.4 |
| 54 | + |
| 55 | + - uses: actions/setup-python@v5 |
| 56 | + with: |
| 57 | + python-version: 3.11 |
| 58 | + cache: 'poetry' |
| 59 | + |
| 60 | + - name: Unsubscribe MNS |
| 61 | + working-directory: './lambdas/mns_subscription' |
| 62 | + env: |
| 63 | + SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }} |
| 64 | + run: | |
| 65 | + poetry install --no-root |
| 66 | +
|
| 67 | + echo "Unsubscribing SQS to MNS for notifications..." |
| 68 | + make unsubscribe |
| 69 | +
|
| 70 | + - name: Terraform Destroy |
| 71 | + working-directory: ${{ vars.TERRAFORM_DIR_PATH }} |
| 72 | + run: | |
| 73 | + make destroy apigee_environment=$APIGEE_ENVIRONMENT environment=$BACKEND_ENVIRONMENT sub_environment=$BACKEND_SUB_ENVIRONMENT |
0 commit comments