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
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
0 commit comments