Skip to content

Commit f35ca6f

Browse files
[NDR-71] Refactor Terraform plan output handling to hide sensitive values
1 parent a2330ce commit f35ca6f

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

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

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,21 +72,6 @@ jobs:
7272
run: |
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
75-
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
76-
working-directory: ./infrastructure
77-
shell: bash
78-
79-
- name: Truncate Plan Output
80-
id: plan-truncated
81-
if: success() || failure()
82-
env:
83-
LENGTH: 64512
84-
run: |
85-
PLAN_FULL=$(grep -v 'Refreshing state...' <<'EOF'
86-
${{ steps.plan.outputs.stdout }}
87-
${{ steps.plan.outputs.stderr }}
88-
EOF
89-
)
9075
9176
# Mask AWS account IDs (12-digit numbers)
9277
echo "$PLAN_FULL" | grep -oE '[0-9]{12}' | while read -r account_id; do
@@ -115,6 +100,22 @@ jobs:
115100
# Mask Terraform variables
116101
echo "::add-mask::${{ vars.TF_VARS_FILE }}"
117102
103+
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
104+
working-directory: ./infrastructure
105+
shell: bash
106+
107+
- name: Truncate Plan Output
108+
id: plan-truncated
109+
if: success() || failure()
110+
env:
111+
LENGTH: 64512
112+
run: |
113+
PLAN_FULL=$(grep -v 'Refreshing state...' <<'EOF'
114+
${{ steps.plan.outputs.stdout }}
115+
${{ steps.plan.outputs.stderr }}
116+
EOF
117+
)
118+
118119
# Optionally redact sensitive strings in the PLAN_FULL variable
119120
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E 's/[0-9]{12}/[REDACTED_AWS_ACCOUNT_ID]/g')
120121
PLAN_FULL=$(echo "$PLAN_FULL" | sed -E 's#https://[a-zA-Z0-9.-]+\.lambda\.amazonaws\.com/[a-zA-Z0-9/._-]+#[REDACTED_LAMBDA_URL]#g')

0 commit comments

Comments
 (0)