Skip to content

Commit 11f26cf

Browse files
fix(tf-checks): control terraform plan output based on show_plan flag (#349)
Co-authored-by: Sunny-Mor <sunnymor830@gmail.com>
1 parent da19d5a commit 11f26cf

2 files changed

Lines changed: 25 additions & 6 deletions

File tree

.github/workflows/tf-checks.yml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ on:
4343
type: boolean
4444
default: false
4545
description: 'Enable terraform plan step.'
46+
show_plan:
47+
required: false
48+
type: boolean
49+
default: true
50+
description: 'Show full terraform plan output. If false, only shows summary (e.g. Plan: 4 to add, 1 to change).'
4651
gcp_credentials:
4752
required: false
4853
type: string
@@ -270,20 +275,30 @@ jobs:
270275
path: ${{ inputs.working_directory }}
271276

272277
- name: 📋 Terraform Plan
273-
if: ${{ inputs.enable_plan }}
274278
id: tf-plan
279+
if: ${{ inputs.enable_plan }}
275280
run: |
276281
export exitcode=0
277282
cd ${{ inputs.working_directory }}
283+
278284
if [ -n "${{ inputs.var_file }}" ]; then
279-
terraform plan -detailed-exitcode -no-color -out tfplan --var-file=${{ inputs.var_file }} || export exitcode=$?
285+
terraform plan -detailed-exitcode -no-color -out=tfplan --var-file=${{ inputs.var_file }} > plan.txt 2>&1 || exitcode=$?
280286
else
281-
terraform plan -detailed-exitcode -no-color -out tfplan || export exitcode=$?
287+
terraform plan -detailed-exitcode -no-color -out=tfplan > plan.txt 2>&1 || exitcode=$?
282288
fi
283-
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
289+
284290
if [ $exitcode -eq 1 ]; then
285-
echo Terraform Plan Failed!
291+
echo "Terraform Plan Failed!"
292+
cat plan.txt
286293
exit 1
294+
fi
295+
296+
echo "exitcode=$exitcode" >> $GITHUB_OUTPUT
297+
298+
if [ "${{ inputs.show_plan }}" == "true" ]; then
299+
# Show full plan
300+
cat plan.txt
287301
else
288-
exit 0
302+
# Show only summary
303+
grep -E '^Plan:|^No changes' plan.txt || echo "No changes."
289304
fi

docs/tf-checks.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
working_directory: './examples/complete/'
4848
provider: 'aws'
4949
enable_plan: true
50+
show_plan: false
5051
var_file: 'vars/dev.tfvars'
5152
aws_region: 'us-east-1'
5253
secrets:
@@ -93,6 +94,7 @@ jobs:
9394
working_directory: './examples/complete/'
9495
provider: 'azurerm'
9596
enable_plan: true
97+
show_plan: false
9698
secrets:
9799
AZURE_CREDENTIALS: ${{ secrets.AZURE_CREDENTIALS }}
98100
GITHUB: ${{ secrets.GITHUB }}
@@ -113,6 +115,7 @@ jobs:
113115
working_directory: './examples/complete/'
114116
provider: 'aws'
115117
enable_plan: true
118+
show_plan: false
116119
aws_region: 'us-east-1'
117120
secrets:
118121
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
@@ -173,6 +176,7 @@ jobs:
173176
| `terraform_version` | No | Latest | Specific Terraform version to use |
174177
| `enable_version_check` | No | `false` | Enable min/max version compatibility testing |
175178
| `enable_plan` | No | `false` | Enable terraform plan step |
179+
| `show_plan` | No | `true` | Only shows terraform plan summary |
176180
| `role_duration_seconds` | No | `3600` | AWS role duration in seconds (900-43200) |
177181
| `project_id` | No | - | GCP project ID |
178182
| `token_format` | No | `access_token` | GCP token format (`access_token` or `id_token`) |

0 commit comments

Comments
 (0)