@@ -39,33 +39,39 @@ jobs:
3939 id : plan
4040 working-directory : ./terraform/common
4141 run : |
42+ #!/bin/bash
4243 set +e
44+
4345 terraform plan -no-color -detailed-exitcode > plan_full.txt 2>&1
44- exit_code =$?
45- set -e
46+ TERRAFORM_EXIT_CODE =$?
47+
4648 cat plan_full.txt
47-
48- resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50)
49- plan_summary=$(grep -E '^Plan:' plan_full.txt)
50-
49+
50+ resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50 || echo "No resource changes" )
51+ plan_summary=$(grep -E '^Plan:' plan_full.txt || echo "No plan summary" )
52+
5153 {
5254 echo "summary_output<<EOF"
5355 echo "$resource_summary"
5456 echo "$plan_summary"
5557 echo "EOF"
5658 } >> "$GITHUB_OUTPUT"
57-
58- if [ "$exit_code" -eq 0 ]; then
59- echo "✅ Terraform plan completed with no changes."
60- echo "plan_status=success" >> $GITHUB_OUTPUT
61- elif [ "$exit_code" -eq 2 ]; then
62- echo "✅ Terraform plan completed with changes."
63- echo "plan_status=changes" >> $GITHUB_OUTPUT
64- elif [ "$exit_code" -eq 1 ]; then
65- echo "❌ Terraform plan failed with errors."
66- echo "plan_status=error" >> $GITHUB_OUTPUT
67- fi
68-
59+
60+ case $TERRAFORM_EXIT_CODE in
61+ 0)
62+ echo "✅ Terraform plan completed with no changes."
63+ echo "plan_status=success" >> $GITHUB_OUTPUT
64+ ;;
65+ 2)
66+ echo "✅ Terraform plan completed with changes."
67+ echo "plan_status=changes" >> $GITHUB_OUTPUT
68+ ;;
69+ *)
70+ echo "❌ Terraform plan failed with errors."
71+ echo "plan_status=error" >> $GITHUB_OUTPUT
72+ ;;
73+ esac
74+
6975 exit 0
7076
7177 - name : Upload full plan as artifact
@@ -106,33 +112,39 @@ jobs:
106112 id : plan
107113 working-directory : ./terraform/dev
108114 run : |
115+ #!/bin/bash
109116 set +e
117+
110118 terraform plan -no-color -detailed-exitcode > plan_full.txt 2>&1
111- exit_code =$?
112- set -e
119+ TERRAFORM_EXIT_CODE =$?
120+
113121 cat plan_full.txt
114-
115- resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50)
116- plan_summary=$(grep -E '^Plan:' plan_full.txt)
117-
122+
123+ resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50 || echo "No resource changes" )
124+ plan_summary=$(grep -E '^Plan:' plan_full.txt || echo "No plan summary" )
125+
118126 {
119127 echo "summary_output<<EOF"
120128 echo "$resource_summary"
121129 echo "$plan_summary"
122130 echo "EOF"
123131 } >> "$GITHUB_OUTPUT"
124-
125- if [ "$exit_code" -eq 0 ]; then
126- echo "✅ Terraform plan completed with no changes."
127- echo "plan_status=success" >> $GITHUB_OUTPUT
128- elif [ "$exit_code" -eq 2 ]; then
129- echo "✅ Terraform plan completed with changes."
130- echo "plan_status=changes" >> $GITHUB_OUTPUT
131- elif [ "$exit_code" -eq 1 ]; then
132- echo "❌ Terraform plan failed with errors."
133- echo "plan_status=error" >> $GITHUB_OUTPUT
134- fi
135-
132+
133+ case $TERRAFORM_EXIT_CODE in
134+ 0)
135+ echo "✅ Terraform plan completed with no changes."
136+ echo "plan_status=success" >> $GITHUB_OUTPUT
137+ ;;
138+ 2)
139+ echo "✅ Terraform plan completed with changes."
140+ echo "plan_status=changes" >> $GITHUB_OUTPUT
141+ ;;
142+ *)
143+ echo "❌ Terraform plan failed with errors."
144+ echo "plan_status=error" >> $GITHUB_OUTPUT
145+ ;;
146+ esac
147+
136148 exit 0
137149
138150 - name : Upload full plan as artifact
@@ -173,33 +185,39 @@ jobs:
173185 id : plan
174186 working-directory : ./terraform/prod
175187 run : |
188+ #!/bin/bash
176189 set +e
190+
177191 terraform plan -no-color -detailed-exitcode > plan_full.txt 2>&1
178- exit_code =$?
179- set -e
192+ TERRAFORM_EXIT_CODE =$?
193+
180194 cat plan_full.txt
181-
182- resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50)
183- plan_summary=$(grep -E '^Plan:' plan_full.txt)
184-
195+
196+ resource_summary=$(grep -E '^(# | [~+\-])' plan_full.txt | head -n 50 || echo "No resource changes" )
197+ plan_summary=$(grep -E '^Plan:' plan_full.txt || echo "No plan summary" )
198+
185199 {
186200 echo "summary_output<<EOF"
187201 echo "$resource_summary"
188202 echo "$plan_summary"
189203 echo "EOF"
190204 } >> "$GITHUB_OUTPUT"
191-
192- if [ "$exit_code" -eq 0 ]; then
193- echo "✅ Terraform plan completed with no changes."
194- echo "plan_status=success" >> $GITHUB_OUTPUT
195- elif [ "$exit_code" -eq 2 ]; then
196- echo "✅ Terraform plan completed with changes."
197- echo "plan_status=changes" >> $GITHUB_OUTPUT
198- elif [ "$exit_code" -eq 1 ]; then
199- echo "❌ Terraform plan failed with errors."
200- echo "plan_status=error" >> $GITHUB_OUTPUT
201- fi
202-
205+
206+ case $TERRAFORM_EXIT_CODE in
207+ 0)
208+ echo "✅ Terraform plan completed with no changes."
209+ echo "plan_status=success" >> $GITHUB_OUTPUT
210+ ;;
211+ 2)
212+ echo "✅ Terraform plan completed with changes."
213+ echo "plan_status=changes" >> $GITHUB_OUTPUT
214+ ;;
215+ *)
216+ echo "❌ Terraform plan failed with errors."
217+ echo "plan_status=error" >> $GITHUB_OUTPUT
218+ ;;
219+ esac
220+
203221 exit 0
204222
205223 - name : Upload full plan as artifact
0 commit comments