Skip to content

Commit b95ebda

Browse files
committed
#43 Terraform Planの出力をファイルに保存し、SNS通知メッセージを詳細化
1 parent bbf322c commit b95ebda

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

.github/workflows/tfdrift.yaml

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,28 @@ jobs:
4343
id: plan
4444
run: |
4545
cd example/actions/terraform
46-
terraform plan -detailed-exitcode
46+
terraform plan -detailed-exitcode -no-color > /tmp/plan_output.txt 2>&1 || echo "exit_code=$?" >> $GITHUB_OUTPUT
47+
cat /tmp/plan_output.txt
4748
4849
- name: Send SNS Notification on Plan Failure
4950
if: ${{ failure() }}
5051
run: |
52+
PLAN_OUTPUT=$(cat /tmp/plan_output.txt | head -50)
53+
5154
aws sns publish \
5255
--topic-arn "arn:aws:sns:ap-northeast-2:456247443832:cn-practice-drift-notification" \
5356
--subject "Terraform Plan Failed - Drift Detection" \
54-
--message "Terraform plan failed during drift detection. Please check the GitHub Actions logs for details. Workflow: ${{ github.workflow }}, Run ID: ${{ github.run_id }}"
57+
--message "$(cat <<EOF
58+
Terraform plan failed during drift detection.
59+
60+
Workflow: ${{ github.workflow }}
61+
Run ID: ${{ github.run_id }}
62+
Repository: ${{ github.repository }}
63+
Branch: ${{ github.ref_name }}
64+
65+
Plan Output (first 50 lines):
66+
${PLAN_OUTPUT}
67+
68+
Full logs: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
69+
EOF
70+
)"

0 commit comments

Comments
 (0)