6161 - name : Run Terraform Plan
6262 id : plan
6363 run : |
64- terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan > plan_output.txt 2>&1
64+ terraform plan -lock-timeout=20m - input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan > plan_output.txt 2>&1
6565 terraform show -no-color tf.plan > tfplan.txt 2>&1
6666
6767 # Mask PEM certificates (BEGIN...END CERTIFICATE)
@@ -202,7 +202,7 @@ jobs:
202202 # Terraform apply will only occur on a push (merge request completion)
203203 - name : Run Terraform Apply
204204 if : github.ref == 'refs/heads/main'
205- run : terraform apply -auto-approve -input=false tf.plan
205+ run : terraform apply -lock-timeout=20m - auto-approve -input=false tf.plan
206206 working-directory : ./infrastructure
207207
208208 deploy_lambdas :
@@ -220,3 +220,68 @@ jobs:
220220 uses : NHSDigital/national-document-repository/.github/workflows/ui-dev-to-main-ci.yml@main
221221 secrets :
222222 AWS_ASSUME_ROLE : ${{ secrets.AWS_ASSUME_ROLE }}
223+
224+ notify-slack :
225+ runs-on : ubuntu-latest
226+ needs : [terraform_plan_apply, deploy_lambdas, deploy_ui]
227+ if : failure() && github.event_name == 'push' && github.ref == 'refs/heads/main'
228+ steps :
229+ - name : Configure AWS Credentials
230+ uses : aws-actions/configure-aws-credentials@v5
231+ with :
232+ role-to-assume : ${{ secrets.AWS_ASSUME_ROLE }}
233+ aws-region : ${{ vars.AWS_REGION }}
234+
235+ - name : Get slack bot token from SSM parameter store
236+ run : |
237+ slack_bot_token=$(aws ssm get-parameter --name "/ndr/alerting/slack/bot_token" --with-decryption --query "Parameter.Value" --output text)
238+ echo "::add-mask::$slack_bot_token"
239+ echo "SLACK_BOT_TOKEN=$slack_bot_token" >> $GITHUB_ENV
240+
241+ - name : Send Slack Notification
242+ 243+ with :
244+ method : chat.postMessage
245+ token : ${{ env.SLACK_BOT_TOKEN }}
246+ payload : |
247+ {
248+ "channel": "${{ vars.ALERTS_SLACK_CHANNEL_ID }}",
249+ "attachments": [
250+ {
251+ "color": "#ff0000",
252+ "blocks": [
253+ {
254+ "type": "header",
255+ "text": {
256+ "type": "plain_text",
257+ "text": "❌ Workflow `${{ github.workflow }}` failed"
258+ }
259+ },
260+ {
261+ "type": "section",
262+ "text": {
263+ "type": "mrkdwn",
264+ "text": "*Triggered by:* `${{ github.actor }}`\n*Branch:* `${{ github.ref_name }}`\n*Workflow:* <${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}|${{ github.workflow }}>"
265+ }
266+ },
267+ {
268+ "type": "divider"
269+ },
270+ {
271+ "type": "section",
272+ "fields": [
273+ { "type": "mrkdwn", "text": "*terraform_plan_apply:* ${{ needs.terraform_plan_apply.result == 'success' && ':white_check_mark:' || ':x:' }}" },
274+ { "type": "mrkdwn", "text": "*deploy_lambdas:* ${{ needs.deploy_lambdas.result == 'success' && ':white_check_mark:' || ':x:' }}" },
275+ { "type": "mrkdwn", "text": "*deploy_ui:* ${{ needs.deploy_ui.result == 'success' && ':white_check_mark:' || ':x:' }}" }
276+ ]
277+ },
278+ {
279+ "type": "context",
280+ "elements": [
281+ { "type": "mrkdwn", "text": "Environment: `development` | Sandbox: `ndr-dev`" }
282+ ]
283+ }
284+ ]
285+ }
286+ ]
287+ }
0 commit comments