Skip to content

Commit efa6397

Browse files
committed
VED-809: Creating teardown pipeline in Github Actions
1 parent d4256fb commit efa6397

File tree

3 files changed

+58
-201
lines changed

3 files changed

+58
-201
lines changed

.github/workflows/continuous-disintegration.yml

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/workflows/pr-teardown.yml

Lines changed: 58 additions & 97 deletions
Original file line numberDiff line numberDiff line change
@@ -6,107 +6,68 @@ on:
66
workflow_dispatch:
77
inputs:
88
pr_number:
9-
description: 'PR number (required for manual runs)'
10-
required: false
9+
description: The PR number of the environment to teardown
10+
required: true
11+
type: string
1112

1213
jobs:
1314
teardown:
1415
name: PR Teardown
1516
runs-on: ubuntu-latest
16-
timeout-minutes: 30
17+
environment:
18+
name: dev
1719
env:
18-
AWS_REGION: ${{ secrets.AWS_REGION || 'eu-west-2' }}
1920
APIGEE_ENVIRONMENT: internal-dev
20-
21-
steps:
22-
- name: Checkout
23-
uses: actions/checkout@v4
24-
25-
- name: Set workspace tag
26-
id: set-workspace
27-
run: |
28-
# PR number comes from event (pull_request) or workflow_dispatch input
29-
PR_NUMBER=${{ github.event.pull_request.number || github.event.inputs.pr_number }}
30-
if [ -z "$PR_NUMBER" ]; then
31-
echo "No PR number found. Provide via workflow_dispatch input 'pr_number' or run from a PR event."
32-
exit 1
33-
fi
34-
WORKSPACE="pr-${PR_NUMBER}"
35-
echo "PR_NUMBER=${PR_NUMBER}" >> $GITHUB_ENV
36-
echo "WORKSPACE=${WORKSPACE}" >> $GITHUB_ENV
37-
echo "Set WORKSPACE=$WORKSPACE"
38-
39-
- name: Assume AWS role
40-
id: assume-role
41-
uses: aws-actions/configure-aws-credentials@v2
42-
with:
43-
# Role ARN = arn:aws:iam::<account-id>:role/<role-name>
44-
role-to-assume: arn:aws:iam::${{ secrets.AWS_DEV_ACCOUNT_ID }}:role/${{ secrets.AWS_ASSUME_ROLE_NAME }}
45-
aws-region: ${{ env.AWS_REGION }}
46-
# Note: configure-aws-credentials supports OIDC or long-lived secrets depending on repo config.
47-
48-
- name: Set AWS default region and APIGEE environment
49-
run: |
50-
echo "AWS_DEFAULT_REGION=${{ env.AWS_REGION }}" >> $GITHUB_ENV
51-
echo "APIGEE_ENVIRONMENT=${{ env.APIGEE_ENVIRONMENT }}" >> $GITHUB_ENV
52-
53-
- name: Init Terraform and extract MNS values
54-
id: init-terraform
55-
env:
56-
AWS_PROFILE: apim-dev
57-
run: |
58-
set -euo pipefail
59-
cd terraform
60-
# Use make to init and create the workspace
61-
make init apigee_environment=internal-dev environment=dev sub_environment="$WORKSPACE"
62-
make workspace apigee_environment=internal-dev environment=dev sub_environment="$WORKSPACE"
63-
64-
# Extract values from Terraform state before destroying
65-
ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)
66-
echo "ID_SYNC_QUEUE_ARN=$ID_SYNC_QUEUE_ARN" >> $GITHUB_ENV
67-
echo "Extracted ID_SYNC_QUEUE_ARN=$ID_SYNC_QUEUE_ARN"
68-
69-
- name: Unsubscribe MNS
70-
env:
71-
AWS_PROFILE: apim-dev
72-
SQS_ARN: ${{ env.ID_SYNC_QUEUE_ARN }}
73-
run: |
74-
set -euo pipefail
75-
cd lambdas/mns_subscription
76-
77-
# Use setup-python in a separate step or install here
78-
python3 -m pip install --upgrade pip
79-
python3 -m pip install poetry
80-
81-
# Prefer the repo's pyproject/poetry files
82-
poetry install --no-root
83-
84-
echo "Unsubscribing SQS to MNS for notifications..."
85-
make unsubscribe
86-
87-
- name: Destroy terraform PR workspace and linked resources
88-
env:
89-
AWS_PROFILE: apim-dev
90-
run: |
91-
set -euo pipefail
92-
cd terraform
93-
94-
# Retry destroy up to 2 times (similar to retryCountOnTaskFailure: 2)
95-
ATTEMPTS=0
96-
until [ $ATTEMPTS -ge 2 ]
97-
do
98-
if make destroy apigee_environment=internal-dev environment=dev sub_environment="$WORKSPACE"; then
99-
echo "Terraform destroy succeeded"
100-
break
101-
fi
102-
ATTEMPTS=$((ATTEMPTS+1))
103-
echo "Retrying terraform destroy (attempt $((ATTEMPTS+1)))"
104-
sleep 3
105-
done
106-
107-
if [ $ATTEMPTS -ge 2 ]; then
108-
echo "Terraform destroy failed after retries"
109-
exit 1
110-
fi
111-
112-
# end job
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+
echo "ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)" >> $GITHUB_ENV
50+
echo "Extracted ID_SYNC_QUEUE_ARN=$ID_SYNC_QUEUE_ARN"
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

azure/azure-pr-teardown-pipeline.yml

Lines changed: 0 additions & 81 deletions
This file was deleted.

0 commit comments

Comments
 (0)