Skip to content

Commit

Permalink
fix: improve error handling and output management in Terraform Valida…
Browse files Browse the repository at this point in the history
…te action
  • Loading branch information
arnol377 committed Mar 27, 2025
1 parent db6ffa9 commit 6047eb2
Showing 1 changed file with 16 additions and 8 deletions.
24 changes: 16 additions & 8 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,29 +42,37 @@ runs:
id: validate
shell: bash
run: |
cd ${{ inputs.working-directory }}
terraform validate
if [[ $? -ne 0 ]]; then
VALIDATE_EXIT_CODE=$?
if [[ $VALIDATE_EXIT_CODE -ne 0 ]]; then
echo "Terraform validation failed"
echo "is_valid=false" >> $GITHUB_OUTPUT
exit $VALIDATE_EXIT_CODE
else
echo "Terraform validation passed"
echo "is_valid=true" >> $GITHUB_OUTPUT
fi
echo "Terraform validation passed"
echo "is_valid=true" >> $GITHUB_OUTPUT
- name: Terraform Test
id: test
shell: bash
if: steps.validate.outcome == 'success'
run: |
cd ${{ inputs.working-directory }}
terraform test
if [[ $? -ne 0 ]]; then
TEST_EXIT_CODE=$?
if [[ $TEST_EXIT_CODE -ne 0 ]]; then
echo "Terraform tests failed"
echo "tests_passed=false" >> $GITHUB_OUTPUT
else
echo "Terraform tests passed"
echo "tests_passed=true" >> $GITHUB_OUTPUT
fi
echo "Terraform tests passed"
echo "tests_passed=true" >> $GITHUB_OUTPUT
- name: Set Outputs
id: set_outputs
shell: bash
run: |
echo "is_valid=${{ steps.validate.outputs.is_valid }}" >> $GITHUB_ENV
echo "tests_passed=${{ steps.test.outputs.tests_passed }}" >> $GITHUB_ENV
echo "is_valid=$(cat $GITHUB_OUTPUT | grep is_valid | cut -d= -f2)" >> $GITHUB_OUTPUT
echo "tests_passed=$(cat $GITHUB_OUTPUT | grep tests_passed | cut -d= -f2)" >> $GITHUB_OUTPUT

0 comments on commit 6047eb2

Please sign in to comment.