Skip to content

Fix incorrect plan changed report with truncated plans #763

Fix incorrect plan changed report with truncated plans

Fix incorrect plan changed report with truncated plans #763

Workflow file for this run

name: Test terraform-output
on:
- pull_request
permissions:
contents: read
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
jobs:
terraform-output:
runs-on: ubuntu-24.04
name: verify outputs
steps:
- name: Checkout
uses: actions/checkout@v4
with:
persist-credentials: false
- name: Get outputs
uses: ./terraform-output
id: terraform-output
with:
path: tests/workflows/test-output
- name: Verify outputs
env:
MY_NUMBER: ${{ steps.terraform-output.outputs.my_number }}
MY_SENSITIVE_NUMBER: ${{ steps.terraform-output.outputs.my_sensitive_number }}
MY_STRING: ${{ steps.terraform-output.outputs.my_string }}
MY_SENSITIVE_STRING: ${{ steps.terraform-output.outputs.my_sensitive_string }}
MY_MULTILINE_STRING: ${{ steps.terraform-output.outputs.my_multiline_string }}
MY_SENSITIVE_MULTILINE_STRING: ${{ steps.terraform-output.outputs.my_sensitive_multiline_string }}
MY_BOOL: ${{ steps.terraform-output.outputs.my_bool }}
MY_SENSITIVE_BOOL: ${{ steps.terraform-output.outputs.my_sensitive_bool }}
AWKWARD_STRING: ${{ steps.terraform-output.outputs.awkward_string }}
AWKWARD_OBJ: ${{ join(fromJson(steps.terraform-output.outputs.awkward_compound_output).nested.thevalue) }}
MY_OBJECT_FIRST: ${{ fromJson(steps.terraform-output.outputs.my_object).first }}
MY_TUPLE: ${{ join(fromJson(steps.terraform-output.outputs.my_tuple)) }}
MY_SET: ${{ contains(fromJson(steps.terraform-output.outputs.my_set), 'one') }}
JSON_OUTPUT_PATH: ${{ steps.terraform-output.outputs.json_output_path }}
run: |
if [[ "$MY_NUMBER" != "5" ]]; then
echo "::error:: output my_number not set correctly"
exit 1
fi
if [[ "$MY_SENSITIVE_NUMBER" != "6" ]]; then
echo "::error:: output my_sensitive_number not set correctly"
exit 1
fi
if [[ "$MY_STRING" != "hello" ]]; then
echo "::error:: output my_string not set correctly"
exit 1
fi
if [[ "$MY_SENSITIVE_STRING" != "password" ]]; then
echo "::error:: output my_sensitive_string not set correctly"
exit 1
fi
if [[ "$MY_BOOL" != "true" ]]; then
echo "::error:: output my_bool not set correctly"
exit 1
fi
if [[ "$MY_SENSITIVE_BOOL" != "false" ]]; then
echo "::error:: output my_number not set correctly"
exit 1
fi
if [[ "$MY_OBJECT_FIRST" != "one" ]]; then
echo "::error:: fromJson(my_object).first not set correctly"
exit 1
fi
if [[ "$MY_TUPLE" != "one,two" ]]; then
echo "::error:: join(fromJson(my_set)) not set correctly"
exit 1
fi
if [[ "$MY_SET" != "true" ]]; then
echo "::error:: contains(fromJson(my_set)) not set correctly"
exit 1
fi
if [[ "$AWKWARD_STRING" != "hello \"there\", here are some 'quotes'." ]]; then
echo "::error:: awkward_string not set correctly"
exit 1
fi
if [[ "$AWKWARD_OBJ" != "hello \"there\", here are some 'quotes'." ]]; then
echo "::error:: fromJson(awkward_compound_output).nested.thevalue not set correctly"
exit 1
fi
expected_sensitive_multiline="qowicznobnad
trewptonopce
zxicvbnoberg"
if [[ "$expected_sensitive_multiline" != "$MY_SENSITIVE_MULTILINE_STRING" ]]; then
echo "::error:: steps.terraform-output.outputs.my_sensitive_multiline_string not set correctly"
exit 1
fi
expected_multiline="mcnbcvnxdgjt
iyriuytifdcv
pydrtdxfgcvj"
if [[ "$expected_multiline" != "$MY_MULTILINE_STRING" ]]; then
echo "::error:: steps.terraform-output.outputs.my_multiline_string not set correctly"
exit 1
fi
## Check if the JSON output file exists and validate its contents
cat "$JSON_OUTPUT_PATH"
if [[ ! -f "$JSON_OUTPUT_PATH" ]]; then
echo "::error:: JSON output file not found at $JSON_OUTPUT_PATH"
exit 1
fi
# Parse JSON and validate primitive types
JSON_MY_NUMBER=$(jq -r '.my_number' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_NUMBER" != "5" ]]; then
echo "::error:: JSON my_number should be 5, got: $JSON_MY_NUMBER"
exit 1
fi
JSON_MY_STRING=$(jq -r '.my_string' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_STRING" != "hello" ]]; then
echo "::error:: JSON my_string should be 'hello', got: $JSON_MY_STRING"
exit 1
fi
JSON_MY_BOOL=$(jq -r '.my_bool' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_BOOL" != "true" ]]; then
echo "::error:: JSON my_bool should be true, got: $JSON_MY_BOOL"
exit 1
fi
# Validate sensitive values are included in JSON
JSON_MY_SENSITIVE_NUMBER=$(jq -r '.my_sensitive_number' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_SENSITIVE_NUMBER" != "6" ]]; then
echo "::error:: JSON my_sensitive_number should be 6, got: $JSON_MY_SENSITIVE_NUMBER"
exit 1
fi
# List from tolist(toset()) may have different order, so check elements exist
JSON_MY_LIST_HAS_ONE=$(jq -r '.my_list | contains(["one"])' "$JSON_OUTPUT_PATH")
JSON_MY_LIST_HAS_TWO=$(jq -r '.my_list | contains(["two"])' "$JSON_OUTPUT_PATH")
JSON_MY_LIST_LENGTH=$(jq -r '.my_list | length' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_LIST_HAS_ONE" != "true" || "$JSON_MY_LIST_HAS_TWO" != "true" || "$JSON_MY_LIST_LENGTH" != "2" ]]; then
echo "::error:: JSON my_list should contain 'one' and 'two' with length 2"
exit 1
fi
# Validate map/object becomes JSON object
JSON_MY_MAP_FIRST=$(jq -r '.my_map.first' "$JSON_OUTPUT_PATH")
JSON_MY_MAP_SECOND=$(jq -r '.my_map.second' "$JSON_OUTPUT_PATH")
JSON_MY_MAP_THIRD=$(jq -r '.my_map.third' "$JSON_OUTPUT_PATH")
if [[ "$JSON_MY_MAP_FIRST" != "one" || "$JSON_MY_MAP_SECOND" != "two" || "$JSON_MY_MAP_THIRD" != "3" ]]; then
echo "::error:: JSON my_map should have correct key-value pairs"
exit 1
fi