@@ -300,27 +300,62 @@ jobs:
300
300
terraform destroy -auto-approve
301
301
fi
302
302
303
- - name : Notify Slack
304
- if : ${{ always() }}
305
- env :
306
- SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK }}
307
- run : |
308
- if [ "${{ job.status }}" == "success" ]; then
309
- STATUS="Success ✅"
310
- COLOR="good"
311
- MESSAGE="Terraform deployment completed successfully."
312
- else
313
- STATUS="Failed ❌"
314
- COLOR="danger"
315
- MESSAGE="Terraform deployment failed. Check logs for details."
316
- fi
303
+ # - name: Notify Slack
304
+ # if: ${{ always() }}
305
+ # env:
306
+ # SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
307
+ # run: |
308
+ # if [ "${{ job.status }}" == "success" ]; then
309
+ # STATUS="Success ✅"
310
+ # COLOR="good"
311
+ # MESSAGE="Terraform deployment completed successfully."
312
+ # else
313
+ # STATUS="Failed ❌"
314
+ # COLOR="danger"
315
+ # MESSAGE="Terraform deployment failed. Check logs for details."
316
+ # fi
317
+
318
+ # RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
317
319
318
- RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
320
+ # curl -X POST -H 'Content-type: application/json' \
321
+ # --data "$(jq -n --arg color "$COLOR" --arg status "$STATUS" --arg message "$MESSAGE" \
322
+ # --arg repo "$GITHUB_REPOSITORY" --arg branch "$GITHUB_REF_NAME" --arg sha "$GITHUB_SHA" \
323
+ # --arg run_url "$RUN_URL" \
324
+ # '{attachments: [{color: $color, title: ("Terraform Deployment: " + $status), text: $message, fields: [{title: "Repository", value: $repo, short: true}, {title: "Branch", value: $branch, short: true}, {title: "Commit", value: $sha, short: true}, {title: "Run URL", value: $run_url, short: false}]}]}')" \
325
+ # $SLACK_WEBHOOK_URL
319
326
320
- curl -X POST -H 'Content-type: application/json' \
321
- --data "$(jq -n --arg color "$COLOR" --arg status "$STATUS" --arg message "$MESSAGE" \
322
- --arg repo "$GITHUB_REPOSITORY" --arg branch "$GITHUB_REF_NAME" --arg sha "$GITHUB_SHA" \
323
- --arg run_url "$RUN_URL" \
324
- '{attachments: [{color: $color, title: ("Terraform Deployment: " + $status), text: $message, fields: [{title: "Repository", value: $repo, short: true}, {title: "Branch", value: $branch, short: true}, {title: "Commit", value: $sha, short: true}, {title: "Run URL", value: $run_url, short: false}]}]}')" \
325
- $SLACK_WEBHOOK_URL
327
+ - name : Notify Slack
328
+ if : ${{ always() }}
329
+ env :
330
+ SLACK_WEBHOOK_URL : ${{ secrets.SLACK_WEBHOOK }}
331
+ run : |
332
+ # Determine the operation type (apply or destroy) using a custom environment variable or flag
333
+ if [[ "${{ inputs.destroy }}" == "true" ]]; then
334
+ OPERATION="Destroy"
335
+ else
336
+ OPERATION="Apply"
337
+ fi
338
+
339
+ # Check the job status
340
+ if [ "${{ job.status }}" == "success" ]; then
341
+ STATUS="Success ✅"
342
+ COLOR="good"
343
+ MESSAGE="Terraform $OPERATION completed successfully."
344
+ else
345
+ STATUS="Failed ❌"
346
+ COLOR="danger"
347
+ MESSAGE="Terraform $OPERATION failed. Check logs for details."
348
+ fi
349
+
350
+ # Create the Run URL
351
+ RUN_URL="${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}"
352
+
353
+ # Send the notification to Slack
354
+ curl -X POST -H 'Content-type : application/json' \
355
+ --data "$(jq -n --arg color "$COLOR" --arg status "$STATUS" --arg message "$MESSAGE" \
356
+ --arg operation "$OPERATION" --arg repo "$GITHUB_REPOSITORY" --arg branch "$GITHUB_REF_NAME" --arg sha "$GITHUB_SHA" \
357
+ --arg run_url "$RUN_URL" \
358
+ ' {attachments: [{color: $color, title: ("Terraform " + $operation + ": " + $status), text: $message, fields: [{title: "Operation", value: $operation, short: true}, {title: "Repository", value: $repo, short: true}, {title: "Branch", value: $branch, short: true}, {title: "Commit", value: $sha, short: true}, {title: "Run URL", value: $run_url, short: false}]}]}' )" \
359
+ $SLACK_WEBHOOK_URL
360
+
326
361
...
0 commit comments