@@ -240,7 +240,7 @@ runs:
240240 write_output terraform_version "$TFV"
241241 write_output workspace "$WS"
242242
243- - name : Summary
243+ - name : Terraform Summary
244244 if : inputs.show_summary != 'false'
245245 continue-on-error : true
246246 shell : bash
@@ -258,9 +258,7 @@ runs:
258258 run : |
259259 set -eo pipefail
260260 [[ "$LIMIT" =~ ^[0-9]+$ ]] || LIMIT=50
261-
262- WS="${TF_WORKSPACE:-}"
263- [ -z "$WS" ] && WS="default"
261+ WS="${TF_WORKSPACE:-}"; [ -z "$WS" ] && WS="default"
264262
265263 {
266264 echo "## 🛠️ Terraform Execution Summary"
@@ -275,107 +273,44 @@ runs:
275273 [ -n "${AWS_REGION:-}" ] && echo "- **AWS region (vars):** \`${AWS_REGION}\`"
276274 } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
277275
278- if [ "${TF_COMMAND:-}" = "plan" ] && [ -f tfplan ]; then
279- if command -v jq >/dev/null 2>&1; then
280- terraform show -json tfplan > /tmp/plan.json || true
281-
282- ADDS=$(jq '[.resource_changes[]? | select(.change.actions == ["create"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
283- UPDS=$(jq '[.resource_changes[]? | select(.change.actions == ["update"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
284- REPL=$(jq '[.resource_changes[]? | select(.change.actions == ["delete","create"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
285- DELS=$(jq '[.resource_changes[]? | select(.change.actions == ["delete"])] | length' /tmp/plan.json 2>/dev/null || echo 0)
286- TOTAL=$((ADDS+UPDS+REPL+DELS))
276+ if [ "${TF_COMMAND:-}" = "plan" ] && [ -f tfplan ] && command -v terraform >/dev/null 2>&1; then
277+ terraform show -no-color tfplan > /tmp/plan.txt || true
287278
288- {
289- echo
290- echo "### 📋 Change summary"
291- echo "- ➕ **create:** ${ADDS}"
292- echo "- ✏️ **update:** ${UPDS}"
293- echo "- 🔁 **replace:** ${REPL}"
294- echo "- ➖ **delete:** ${DELS}"
295- echo "- **total:** ${TOTAL}"
296- } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
297-
298- {
299- echo
300- echo "### 🔎 Top ${LIMIT} changes"
301- echo
302- jq -r --argjson limit "$LIMIT" '
303- .resource_changes // [] |
304- map({addr: .address, act: .change.actions}) |
305- map({
306- addr,
307- badge:
308- (if .act==["create"] then "➕ create"
309- elif .act==["update"] then "✏️ update"
310- elif .act==["delete","create"] then "🔁 replace"
311- elif .act==["delete"] then "➖ delete"
312- else (.act|join(",")) end)
313- }) |
314- sort_by(
315- (if .badge|test("^➕") then 0
316- elif .badge|test("^✏️") then 1
317- elif .badge|test("^🔁") then 2
318- elif .badge|test("^➖") then 3
319- else 4 end),
320- .addr
321- ) |
322- .[:$limit] |
323- if length==0 then "*(no resource changes)*"
324- else map("- `\(.addr)` — **\(.badge)**")[] end
325- ' /tmp/plan.json
326- } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
279+ C=$(grep -cE ' will be created$' /tmp/plan.txt || true)
280+ U=$(grep -cE ' will be updated in-place$' /tmp/plan.txt || true)
281+ R=$(grep -cE ' must be replaced$' /tmp/plan.txt || true)
282+ D=$(grep -cE ' will be destroyed$' /tmp/plan.txt || true)
283+ RD=$(grep -cE ' will be read during apply$' /tmp/plan.txt || true)
284+ T=$((C+U+R+D))
327285
328- {
329- echo
330- echo "<details>"
331- echo "<summary>Show attribute-level changes (first ${LIMIT})</summary>"
332- echo
333- echo '```'
334- jq -r --argjson limit "$LIMIT" '
335- .resource_changes // [] |
336- .[:$limit] |
337- .[] |
338- .address as $a |
339- .change.actions as $act |
340- (
341- if $act==["create"] then "CREATE " + $a
342- elif $act==["update"] then "UPDATE " + $a
343- elif $act==["delete","create"] then "REPLACE " + $a
344- elif $act==["delete"] then "DELETE " + $a
345- else ( ($act|join(",")) + " " + $a) end
346- ) as $head |
347- (
348- .change.after_unknown // {} | keys_unsorted[]? |
349- " ~ unknown: " + .
350- ),
351- (
352- .change.before? as $b |
353- .change.after? as $c |
354- ([$b,$c] | any) |
355- if . then
356- ( ($b // {}) as $bb | ($c // {}) as $cc |
357- ( ($bb|keys_unsorted + $cc|keys_unsorted) | unique )[] |
358- select( ($bb[.]|tostring) != ($cc[.]|tostring) ) |
359- " ~ " + .
360- )
361- else empty end
362- )
363- ' /tmp/plan.json
364- echo '```'
365- echo
366- echo "</details>"
367- } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
286+ {
287+ echo
288+ echo "### 📋 Change summary"
289+ echo "- ➕ **create:** ${C}"
290+ echo "- ✏️ **update:** ${U}"
291+ echo "- 🔁 **replace:** ${R}"
292+ echo "- ➖ **delete:** ${D}"
293+ echo "- 📖 **data reads:** ${RD}"
294+ echo "- **total:** ${T}"
295+ } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
368296
369- else
370- TOTAL_LINES=$(terraform show -no-color tfplan | wc -l | awk '{print $1}')
297+ {
298+ echo
299+ echo "### 🔎 Changes (first ${LIMIT})"
300+ echo
301+ awk '
302+ / will be created$/ {addr=$0; sub(/ will be .*/, "", addr); print "- `" addr "` — **create**"; next}
303+ / will be updated in-place$/ {addr=$0; sub(/ will be .*/, "", addr); print "- `" addr "` — **update**"; next}
304+ / must be replaced$/ {addr=$0; sub(/ must be .*/, "", addr); print "- `" addr "` — **replace**"; next}
305+ / will be destroyed$/ {addr=$0; sub(/ will be .*/, "", addr); print "- `" addr "` — **delete**"; next}
306+ ' /tmp/plan.txt | head -n "$LIMIT"
307+ } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
308+
309+ if [ "$T" -eq 0 ]; then
371310 {
372311 echo
373- echo "### 📄 Plan (first ${LIMIT} lines${TOTAL_LINES:+ of ${TOTAL_LINES}})"
374- terraform show -no-color tfplan | sed -n "1,${LIMIT}p"
375- if [ -n "${TOTAL_LINES:-}" ] && [ "$TOTAL_LINES" -gt "$LIMIT" ]; then
376- echo
377- echo "_…truncated, total lines: $TOTAL_LINES_"
378- fi
312+ echo "### 📄 Plan (first ${LIMIT} lines)"
313+ sed -n "1,${LIMIT}p" /tmp/plan.txt
379314 } >> "${GITHUB_STEP_SUMMARY:-/dev/null}" || true
380315 fi
381- fi
316+ fi
0 commit comments