Skip to content

Commit

Permalink
fix: enhance output handling and error reporting in Terraform Validat…
Browse files Browse the repository at this point in the history
…e action
  • Loading branch information
arnol377 committed Mar 27, 2025
1 parent 4cd6dd7 commit 75391f1
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,16 @@ inputs:
outputs:
is_valid:
description: 'Whether the Terraform configuration is valid (true/false)'
value: ${{ steps.validate.outputs.is_valid }}
tests_passed:
description: 'Whether the Terraform tests passed (true/false)'
value: ${{ steps.test.outputs.tests_passed }}
stdout:
description: 'Output from terraform validate and test commands'
value: ${{ steps.set_outputs.outputs.stdout }}
stderr:
description: 'Any error output from terraform validate or test commands'
value: ${{ steps.set_outputs.outputs.stderr }}

runs:
using: "composite"
Expand All @@ -46,11 +50,11 @@ runs:
terraform validate
VALIDATE_EXIT_CODE=$?
if [[ $VALIDATE_EXIT_CODE -ne 0 ]]; then
echo "Terraform validation failed"
echo "is_valid=false" >> $GITHUB_OUTPUT
echo "Terraform validation failed"
else
echo "Terraform validation passed"
echo "is_valid=true" >> $GITHUB_OUTPUT
echo "Terraform validation passed"
fi
- name: Terraform Test
Expand All @@ -61,17 +65,20 @@ runs:
terraform test
TEST_EXIT_CODE=$?
if [[ $TEST_EXIT_CODE -ne 0 ]]; then
echo "Terraform tests failed"
echo "tests_passed=false" >> $GITHUB_OUTPUT
echo "Terraform tests failed"
else
echo "Terraform tests passed"
echo "tests_passed=true" >> $GITHUB_OUTPUT
echo "Terraform tests passed"
fi
- name: Set Final Outputs
id: set_outputs
shell: bash
run: |
echo "is_valid=${{ steps.validate.outputs.is_valid || 'false' }}" >> $GITHUB_OUTPUT
echo "tests_passed=${{ steps.test.outputs.tests_passed || 'false' }}" >> $GITHUB_OUTPUT
echo "stdout=Successfully ran terraform validate and test" >> $GITHUB_OUTPUT
echo "stdout=Terraform validate and test complete" >> $GITHUB_OUTPUT
if [[ "${{ steps.validate.outputs.is_valid }}" != "true" || "${{ steps.test.outputs.tests_passed }}" != "true" ]]; then
echo "stderr=Validation or tests failed" >> $GITHUB_OUTPUT
else
echo "stderr=" >> $GITHUB_OUTPUT
fi

0 comments on commit 75391f1

Please sign in to comment.