Skip to content

Commit ef47871

Browse files
[NDR-71] Enhance masking logic in Terraform plan output to handle missing API URLs, Lambda URLs, and AWS account IDs gracefully
1 parent 141e642 commit ef47871

File tree

1 file changed

+2
-16
lines changed

1 file changed

+2
-16
lines changed

.github/workflows/terraform-dev-to-main-ci.yml

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,12 @@ jobs:
7373
terraform plan -input=false -no-color -var-file="${{vars.TF_VARS_FILE}}" -out tf.plan
7474
terraform show -no-color tf.plan > tfplan.txt
7575
76-
77-
echo "0"
78-
7976
# Mask sensitive URLs in the Terraform Plan output
8077
grep -Eo 'https://[a-zA-Z0-9.-]+\.execute-api\.[a-zA-Z0-9.-]+\.amazonaws\.com/[a-zA-Z0-9/._-]*' tfplan.txt | while read -r api_url; do
8178
if [ -n "$api_url" ]; then
8279
echo "::add-mask::$api_url"
8380
fi
84-
done
85-
86-
echo "1"
81+
done || echo "No api URLs found to mask."
8782
8883
# Mask Lambda invocation URLs
8984
grep -Eo 'https://[a-zA-Z0-9.-]+\.lambda\.amazonaws\.com/[a-zA-Z0-9/._-]+' tfplan.txt | while read -r lambda_url; do
@@ -92,29 +87,20 @@ jobs:
9287
fi
9388
done || echo "No Lambda URLs found to mask."
9489
95-
echo "2"
96-
9790
# Mask AWS account IDs (12-digit numbers)
9891
grep -Eo '[0-9]{12}' tfplan.txt | while read -r account_id; do
9992
if [ -n "$account_id" ]; then
10093
echo "::add-mask::$account_id"
10194
fi
102-
done
103-
104-
echo "3"
95+
done || echo "No Account IDs found to mask."
10596
10697
# Mask GitHub secrets
10798
echo "::add-mask::${{ secrets.AWS_ASSUME_ROLE }}"
10899
echo "::add-mask::${{ secrets.GITHUB_TOKEN }}"
109100
110-
echo "4"
111-
112-
113101
# Mask Terraform variables
114102
echo "::add-mask::${{ vars.TF_VARS_FILE }}"
115103
116-
echo "5"
117-
118104
echo "summary=$(grep -E 'Plan: [0-9]+ to add, [0-9]+ to change, [0-9]+ to destroy\.|No changes\. Your infrastructure matches the configuration\.' tfplan.txt | sed 's/.*No changes\. Your infrastructure matches the configuration/Plan: no changes/g' | sed 's/.*Plan: //g' | sed 's/\..*//g')" >> $GITHUB_OUTPUT
119105
working-directory: ./infrastructure
120106
shell: bash

0 commit comments

Comments
 (0)