|
41 | 41 | MY_OBJECT_FIRST: ${{ fromJson(steps.terraform-output.outputs.my_object).first }} |
42 | 42 | MY_TUPLE: ${{ join(fromJson(steps.terraform-output.outputs.my_tuple)) }} |
43 | 43 | MY_SET: ${{ contains(fromJson(steps.terraform-output.outputs.my_set), 'one') }} |
| 44 | + JSON_OUTPUT_PATH: ${{ steps.terraform-output.outputs.json_output_path }} |
44 | 45 | run: | |
45 | 46 | if [[ "$MY_NUMBER" != "5" ]]; then |
46 | 47 | echo "::error:: output my_number not set correctly" |
@@ -114,3 +115,56 @@ jobs: |
114 | 115 | echo "::error:: steps.terraform-output.outputs.my_multiline_string not set correctly" |
115 | 116 | exit 1 |
116 | 117 | fi |
| 118 | +
|
| 119 | + ## Check if the JSON output file exists and validate its contents |
| 120 | +
|
| 121 | + if [[ ! -f "$JSON_OUTPUT_PATH" ]]; then |
| 122 | + echo "::error:: JSON output file not found at $JSON_OUTPUT_PATH" |
| 123 | + exit 1 |
| 124 | + fi |
| 125 | +
|
| 126 | + # Parse JSON and validate primitive types |
| 127 | + JSON_MY_NUMBER=$(jq -r '.my_number' "$JSON_OUTPUT_PATH") |
| 128 | + if [[ "$JSON_MY_NUMBER" != "5" ]]; then |
| 129 | + echo "::error:: JSON my_number should be 5, got: $JSON_MY_NUMBER" |
| 130 | + exit 1 |
| 131 | + fi |
| 132 | +
|
| 133 | + JSON_MY_STRING=$(jq -r '.my_string' "$JSON_OUTPUT_PATH") |
| 134 | + if [[ "$JSON_MY_STRING" != "hello" ]]; then |
| 135 | + echo "::error:: JSON my_string should be 'hello', got: $JSON_MY_STRING" |
| 136 | + exit 1 |
| 137 | + fi |
| 138 | +
|
| 139 | + JSON_MY_BOOL=$(jq -r '.my_bool' "$JSON_OUTPUT_PATH") |
| 140 | + if [[ "$JSON_MY_BOOL" != "true" ]]; then |
| 141 | + echo "::error:: JSON my_bool should be true, got: $JSON_MY_BOOL" |
| 142 | + exit 1 |
| 143 | + fi |
| 144 | +
|
| 145 | + # Validate sensitive values are included in JSON |
| 146 | + JSON_MY_SENSITIVE_NUMBER=$(jq -r '.my_sensitive_number' "$JSON_OUTPUT_PATH") |
| 147 | + if [[ "$JSON_MY_SENSITIVE_NUMBER" != "6" ]]; then |
| 148 | + echo "::error:: JSON my_sensitive_number should be 6, got: $JSON_MY_SENSITIVE_NUMBER" |
| 149 | + exit 1 |
| 150 | + fi |
| 151 | +
|
| 152 | + # Validate list becomes array (preserves order) |
| 153 | + JSON_MY_LIST=$(jq -c '.my_list' "$JSON_OUTPUT_PATH") |
| 154 | + # List from tolist(toset()) may have different order, so check elements exist |
| 155 | + JSON_MY_LIST_HAS_ONE=$(jq -r '.my_list | contains(["one"])' "$JSON_OUTPUT_PATH") |
| 156 | + JSON_MY_LIST_HAS_TWO=$(jq -r '.my_list | contains(["two"])' "$JSON_OUTPUT_PATH") |
| 157 | + JSON_MY_LIST_LENGTH=$(jq -r '.my_list | length' "$JSON_OUTPUT_PATH") |
| 158 | + if [[ "$JSON_MY_LIST_HAS_ONE" != "true" || "$JSON_MY_LIST_HAS_TWO" != "true" || "$JSON_MY_LIST_LENGTH" != "2" ]]; then |
| 159 | + echo "::error:: JSON my_list should contain 'one' and 'two' with length 2" |
| 160 | + exit 1 |
| 161 | + fi |
| 162 | +
|
| 163 | + # Validate map/object becomes JSON object |
| 164 | + JSON_MY_MAP_FIRST=$(jq -r '.my_map.first' "$JSON_OUTPUT_PATH") |
| 165 | + JSON_MY_MAP_SECOND=$(jq -r '.my_map.second' "$JSON_OUTPUT_PATH") |
| 166 | + JSON_MY_MAP_THIRD=$(jq -r '.my_map.third' "$JSON_OUTPUT_PATH") |
| 167 | + if [[ "$JSON_MY_MAP_FIRST" != "one" || "$JSON_MY_MAP_SECOND" != "two" || "$JSON_MY_MAP_THIRD" != "3" ]]; then |
| 168 | + echo "::error:: JSON my_map should have correct key-value pairs" |
| 169 | + exit 1 |
| 170 | + fi |
0 commit comments