1- name : Deploy to INT and run E2e test
1+ name : Deploy Template
2+
23on :
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
916jobs :
1017 terraform-plan :
1320 id-token : write
1421 contents : read
1522 steps :
16- - name : Debug OIDC
23+ - name : Connect to AWS
1724 uses : aws-actions/configure-aws-credentials@v4
1825 with :
1926 aws-region : eu-west-2
@@ -34,16 +41,13 @@ jobs:
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 }}
4649 terraform-apply :
50+ if : ${{ vars.SKIP_APPLY != 'true' }}
4751 needs : terraform-plan
4852 runs-on : ubuntu-latest
4953 permissions :
@@ -67,18 +71,14 @@ jobs:
6771
6872 - name : Terraform Init
6973 working-directory : ${{ vars.TERRAFORM_DIR_PATH }}
70- run : |
71- export ENVIRONMENT=${{ inputs.environment }}
72- make init
74+ run : make init apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
7375
7476 - name : Terraform Apply
7577 working-directory : ${{ vars.TERRAFORM_DIR_PATH }}
76- run : |
77- make apply environment=${{ inputs.environment }} aws_account_name=int
78-
78+ run : make plan apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
7979 e2e-tests :
80+ if : ${{ vars.RUN_E2E == 'true' && inputs.environment == vars.ACTIVE_ENVIRONMENT }}
8081 needs : terraform-apply
81- if : ${{ vars.RUN_E2E == 'true' || inputs.environment == vars.ACTIVE_ENVIRONMENT }}
8282 runs-on : ubuntu-latest
8383 permissions :
8484 id-token : write
@@ -93,15 +93,24 @@ jobs:
9393 role-to-assume : arn:aws:iam::${{ vars.AWS_ACCOUNT_ID }}:role/auto-ops
9494 role-session-name : github-actions
9595
96+ - uses : hashicorp/setup-terraform@v3
97+ with :
98+ terraform_version : " 1.12.2"
99+
100+ - name : Terraform Init
101+ working-directory : ${{ vars.TERRAFORM_DIR_PATH }}
102+ run : make init apigee_environment=${{ inputs.apigee_environment }} environment=${{ inputs.environment }} sub_environment=${{ inputs.sub_environment }}
103+
96104 - name : Set up Python
97105 uses : actions/setup-python@v5
98106 with :
99107 python-version : " 3.11"
100108
101109 - name : Install Poetry
102110 run : |
103- curl -sSL https://install.python-poetry.org | python3 -
111+ curl -sSL https://install.python-poetry.org | python3 - --version 2.1.2
104112 echo "$HOME/.local/bin" >> $GITHUB_PATH
113+ poetry --version
105114
106115 - name : Set Poetry to use Python 3.11
107116 working-directory : ${{ vars.E2E_DIR_PATH }}
@@ -113,27 +122,39 @@ jobs:
113122 run : |
114123 poetry install --no-root
115124
125+ - name : Install oathtool
126+ run : sudo apt-get update && sudo apt-get install -y oathtool
127+
128+ - name : Get JWT token for apigee
129+ env :
130+ APIGEE_USERNAME : ${{ vars.APIGEE_USERNAME }}
131+ APIGEE_PASSWORD : ${{ secrets.APIGEE_PASSWORD }}
132+ APIGEE_OAUTH_TOKEN : ${{ secrets.APIGEE_BASIC_AUTH_TOKEN }}
133+ APIGEE_OTP_SECRET : ${{ secrets.APIGEE_OTP_KEY }}
134+ run : |
135+ CODE=$(oathtool --totp -b "$APIGEE_OTP_SECRET")
136+ echo "::add-mask::$CODE"
137+ echo "Requesting access token from Apigee..."
138+ response=$(curl -s -X POST "https://login.apigee.com/oauth/token" \
139+ -H "Content-Type: application/x-www-form-urlencoded" \
140+ -H "Accept: application/json;charset=utf-8" \
141+ -H "Authorization: Basic $APIGEE_BASIC_AUTH_TOKEN" \
142+ -d "username=$APIGEE_USERNAME&password=$APIGEE_PASSWORD&mfa_token=$CODE&grant_type=password")
143+ token=$(echo "$response" | jq -e -r '.access_token')
144+ if [[ -z "$token" ]]; then
145+ echo "Failed to retrieve access token"
146+ exit 1
147+ fi
148+ echo "::add-mask::$token"
149+ echo "APIGEE_ACCESS_TOKEN=$token" >> $GITHUB_ENV
150+
116151 - name : Run e2e tests
117152 working-directory : ${{ vars.E2E_DIR_PATH }}
153+ env :
154+ APIGEE_ACCESS_TOKEN : ${{ env.APIGEE_ACCESS_TOKEN }}
155+ APIGEE_USERNAME :
[email protected] 118156 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-
157+ export APIGEE_ENVIRONMENT=internal-dev
158+ export PROXY_NAME=immunisation-fhir-api-int-${{ inputs.environment }}
159+ export SERVICE_BASE_PATH=immunisation-fhir-api/FHIR/R4-int-${{ inputs.environment }}
139160 make run-immunization
0 commit comments