Skip to content

Commit e5d909b

Browse files
committed
VED-711: Terraform changes for preprod account (#756)
* Use consistent naming for dev / preprod / prod accounts. Rename int blue / green environments to int-blue / int-green. Update pipelines to supply the correct parameters. TF fixes for state import. * Look up VPC by name. Disable MESH in preprod. Use correct cert in preprod. Remove unused vars. * Revert admin role change as this prevents auto-ops from managing KMS keys via TF. * Change back to apply. * Add blue deploy job. Fix e2e test condition. * Add import command * Disable MESH processor in prod. * Change back to apply. Add deletion protection to all DDB tables. * Pin specific commits for external GitHub actions. * Revert change made for local use.
1 parent 8759790 commit e5d909b

File tree

24 files changed

+241
-208
lines changed

24 files changed

+241
-208
lines changed
Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
name: Deploy Blue Green - INT
22

33
on:
4-
pull_request:
5-
types: [closed]
6-
branches: [master]
4+
push:
5+
branches:
6+
- release-2025-08-12
77

88
jobs:
99
deploy-green:
1010
uses: ./.github/workflows/deploy-template.yml
1111
with:
12-
environment: green
13-
12+
apigee_environment: int
13+
environment: preprod
14+
sub_environment: int-green
1415
deploy-blue:
15-
needs: deploy-green
1616
uses: ./.github/workflows/deploy-template.yml
1717
with:
18-
environment: blue
18+
apigee_environment: int
19+
environment: preprod
20+
sub_environment: int-blue
Lines changed: 67 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
name: Deploy to INT and run E2e test
1+
name: Deploy Template
2+
23
on:
34
workflow_call:
45
inputs:
6+
apigee_environment:
7+
required: true
8+
type: string
59
environment:
610
required: true
711
type: string
12+
sub_environment:
13+
required: true
14+
type: string
815

916
jobs:
1017
terraform-plan:
@@ -13,8 +20,8 @@ jobs:
1320
id-token: write
1421
contents: read
1522
steps:
16-
- name: Debug OIDC
17-
uses: aws-actions/configure-aws-credentials@v4
23+
- name: Connect to AWS
24+
uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
1825
with:
1926
aws-region: eu-west-2
2027
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
@@ -24,26 +31,24 @@ jobs:
2431
run: aws sts get-caller-identity
2532

2633
- name: Checkout
27-
uses: actions/checkout@v5
34+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
2835
with:
2936
fetch-depth: 1
3037

31-
- uses: hashicorp/setup-terraform@v3
38+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
3239
with:
3340
terraform_version: "1.12.2"
3441

3542
- name: Terraform Init
3643
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
37-
run: |
38-
export ENVIRONMENT=${{ inputs.environment }}
39-
make init
44+
run: make init apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
4045

4146
- name: Terraform Plan
4247
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
43-
run: |
44-
make plan environment=${{ inputs.environment }} aws_account_name=int
45-
48+
run: make plan apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
49+
# TODO - save the plan and use it in the apply step
4650
terraform-apply:
51+
if: ${{ vars.SKIP_APPLY != 'true' }}
4752
needs: terraform-plan
4853
runs-on: ubuntu-latest
4954
permissions:
@@ -53,55 +58,61 @@ jobs:
5358
name: int
5459
steps:
5560
- name: Checkout
56-
uses: actions/checkout@v5
61+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
5762

58-
- uses: aws-actions/configure-aws-credentials@v4
63+
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
5964
with:
6065
aws-region: eu-west-2
6166
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
6267
role-session-name: github-actions
6368

64-
- uses: hashicorp/setup-terraform@v3
69+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
6570
with:
6671
terraform_version: "1.12.2"
6772

6873
- name: Terraform Init
6974
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
70-
run: |
71-
export ENVIRONMENT=${{ inputs.environment }}
72-
make init
75+
run: make init apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
7376

7477
- name: Terraform Apply
7578
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
76-
run: |
77-
make apply environment=${{ inputs.environment }} aws_account_name=int
78-
79+
run: make apply apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
80+
# TODO - use a saved plan from the plan step
7981
e2e-tests:
82+
if: ${{ vars.RUN_E2E == 'true' && inputs.sub_environment == vars.ACTIVE_ENVIRONMENT }}
8083
needs: terraform-apply
81-
if: ${{ vars.RUN_E2E == 'true' || inputs.environment == vars.ACTIVE_ENVIRONMENT }}
8284
runs-on: ubuntu-latest
8385
permissions:
8486
id-token: write
8587
contents: read
8688
steps:
8789
- name: Checkout
88-
uses: actions/checkout@v5
90+
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8
8991

90-
- uses: aws-actions/configure-aws-credentials@v4
92+
- uses: aws-actions/configure-aws-credentials@7474bc4690e29a8392af63c5b98e7449536d5c3a
9193
with:
9294
aws-region: eu-west-2
9395
role-to-assume: arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
9496
role-session-name: github-actions
9597

98+
- uses: hashicorp/setup-terraform@b9cd54a3c349d3f38e8881555d616ced269862dd
99+
with:
100+
terraform_version: "1.12.2"
101+
102+
- name: Terraform Init
103+
working-directory: ${{ vars.TERRAFORM_DIR_PATH }}
104+
run: make init apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
105+
96106
- name: Set up Python
97107
uses: actions/setup-python@v5
98108
with:
99109
python-version: "3.11"
100110

101111
- name: Install Poetry
102112
run: |
103-
curl -sSL https://install.python-poetry.org | python3 -
113+
curl -sSL https://install.python-poetry.org | python3 - --version 2.1.2
104114
echo "$HOME/.local/bin" >> $GITHUB_PATH
115+
poetry --version
105116
106117
- name: Set Poetry to use Python 3.11
107118
working-directory: ${{ vars.E2E_DIR_PATH }}
@@ -113,27 +124,39 @@ jobs:
113124
run: |
114125
poetry install --no-root
115126
127+
- name: Install oathtool
128+
run: sudo apt-get update && sudo apt-get install -y oathtool
129+
130+
- name: Get JWT token for apigee
131+
env:
132+
APIGEE_USERNAME: ${{ vars.APIGEE_USERNAME }}
133+
APIGEE_PASSWORD: ${{ secrets.APIGEE_PASSWORD }}
134+
APIGEE_OAUTH_TOKEN: ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
135+
APIGEE_OTP_SECRET: ${{ secrets.APIGEE_OTP_KEY }}
136+
run: |
137+
CODE=$(oathtool --totp -b "$APIGEE_OTP_SECRET")
138+
echo "::add-mask::$CODE"
139+
echo "Requesting access token from Apigee..."
140+
response=$(curl -s -X POST "https://login.apigee.com/oauth/token" \
141+
-H "Content-Type: application/x-www-form-urlencoded" \
142+
-H "Accept: application/json;charset=utf-8" \
143+
-H "Authorization: Basic $APIGEE_BASIC_AUTH_TOKEN" \
144+
-d "username=$APIGEE_USERNAME&password=$APIGEE_PASSWORD&mfa_token=$CODE&grant_type=password")
145+
token=$(echo "$response" | jq -e -r '.access_token')
146+
if [[ -z "$token" ]]; then
147+
echo "Failed to retrieve access token"
148+
exit 1
149+
fi
150+
echo "::add-mask::$token"
151+
echo "APIGEE_ACCESS_TOKEN=$token" >> $GITHUB_ENV
152+
116153
- name: Run e2e tests
117154
working-directory: ${{ vars.E2E_DIR_PATH }}
155+
env:
156+
APIGEE_ACCESS_TOKEN: ${{ env.APIGEE_ACCESS_TOKEN }}
157+
APIGEE_USERNAME: [email protected]
118158
run: |
119-
apigee_token=$(aws ssm get-parameter \
120-
--name "/imms/apigee/non-prod/token" \
121-
--with-decryption \
122-
--query "Parameter.Value" \
123-
--output text)
124-
125-
status_api_key=$(aws ssm get-parameter \
126-
--name "/imms/apigee/non-prod/status-api-key" \
127-
--with-decryption \
128-
--query "Parameter.Value" \
129-
--output text)
130-
131-
export APIGEE_ACCESS_TOKEN=$apigee_token
132-
133-
export APIGEE_ENVIRONMENT=int
134-
export STATUS_API_KEY=$status_api_key
135-
export PROXY_NAME=immunisation-fhir-api-internal-dev
136-
export SERVICE_BASE_PATH=immunisation-fhir-api/FHIR/R4
137-
export SSO_LOGIN_URL=https://login.apigee.com
138-
159+
export APIGEE_ENVIRONMENT=internal-dev
160+
export PROXY_NAME=immunisation-fhir-api-${{ inputs.sub_environment }}
161+
export SERVICE_BASE_PATH=immunisation-fhir-api/FHIR/R4-${{ inputs.sub_environment }}
139162
make run-immunization

azure/azure-pr-teardown-pipeline.yml

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,37 @@ jobs:
4545
4646
- bash: |
4747
export AWS_PROFILE=apim-dev
48-
account_id="$(aws sts get-caller-identity --query Account --output text)"
4948
5049
cd terraform
51-
terraform workspace select $(WORKSPACE)
52-
make init && make destroy aws_account_no=${account_id} environment=$(WORKSPACE)
50+
make init apigee_environment=internal-dev environment=dev sub_environment=$workspace
51+
make workspace apigee_environment=internal-dev environment=dev sub_environment="$WORKSPACE"
52+
53+
# Extract values from Terraform state before destroying
54+
ID_SYNC_QUEUE_ARN=$(make -s output name=id_sync_queue_arn)
55+
echo "##vso[task.setvariable variable=ID_SYNC_QUEUE_ARN]$ID_SYNC_QUEUE_ARN"
56+
displayName: "Init Terraform and extract MNS values"
57+
58+
- bash: |
59+
export AWS_PROFILE=apim-dev
60+
cd mns_subscription
61+
62+
echo "unsubscribing SQS Queue from MNS notifications."
63+
pyenv install -s 3.11.11
64+
pyenv local 3.11.11
65+
echo "Setting up poetry environment..."
66+
poetry env use 3.11
67+
poetry install --no-root
68+
69+
echo "unsubscribing SQS to MNS for notifications.."
70+
make unsubscribe
71+
displayName: "Unsubscribe MNS"
72+
env:
73+
SQS_ARN: "$(ID_SYNC_QUEUE_ARN)"
74+
75+
- bash: |
76+
export AWS_PROFILE=apim-dev
77+
78+
cd terraform
79+
make destroy apigee_environment=internal-dev environment=dev sub_environment=$workspace
5380
displayName: Destroy terraform PR workspace and linked resources
5481
retryCountOnTaskFailure: 2

azure/templates/post-deploy.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@ steps:
5757
echo pr_no: $pr_no
5858
5959
cd terraform
60-
61-
make init
60+
make init environment=${{ parameters.aws_account_type }} sub_environment=$workspace
6261
make apply environment=${{ parameters.aws_account_type }} sub_environment=$workspace
6362
6463
AWS_DOMAIN_NAME=$(make -s output name=service_domain_name)

azure/templates/post-prod-deploy.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ steps:
2626
set -e
2727
if ! [[ $APIGEE_ENVIRONMENT =~ .*-*sandbox ]]; then
2828
export AWS_PROFILE=apim-dev
29-
aws_account_no="$(aws sts get-caller-identity --query Account --output text)"
3029
3130
service_name=$(FULLY_QUALIFIED_SERVICE_NAME)
3231
@@ -35,12 +34,12 @@ steps:
3534
echo sandbox with following parameters:
3635
echo workspace: $workspace
3736
echo AWS environment: $APIGEE_ENVIRONMENT
38-
37+
3938
cd terraform
4039
41-
make init
42-
make apply aws_account_no=${aws_account_no} environment=$workspace
40+
make init environment=${{ parameters.aws_account_type }} sub_environment=$workspace
41+
make apply environment=${{ parameters.aws_account_type }} sub_environment=$workspace
4342
fi
4443
displayName: Apply Terraform
4544
workingDirectory: "$(Pipeline.Workspace)/s/$(SERVICE_NAME)"
46-
retryCountOnTaskFailure: 2
45+
retryCountOnTaskFailure: 2

infra/.terraform.lock.hcl

Lines changed: 16 additions & 56 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

infra/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ ifndef name
4242
endif
4343
$(tf_cmd) output -raw $(name)
4444

45-
import:
45+
import:
4646
$(tf_cmd) import $(tf_vars) $(to) $(id)
4747

4848
tf-%:

0 commit comments

Comments
 (0)