Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve terraform comment output #412

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion terraform-v2/plan.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ terraform -chdir=${module_path} plan -input=false -no-color -detailed-exitcode -
| $COMPACT_PLAN \
>plan.txt

cat plan.txt | sed -E 's/^([[:space:]]+)([-+])/\2\1/g' > diff_friendly_plan.txt

readonly TF_EXIT=${PIPESTATUS[0]}
set -e

Expand All @@ -31,7 +33,7 @@ if [[ -n "$GITHUB_TOKEN" && "<< parameters.add_github_comment >>" == "true" ]];
export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"
export label="<< parameters.label >>"

if ! python3 /tmp/github.py plan <plan.txt; then
if ! python3 /tmp/github.py plan <diff_friendly_plan.txt; then
echo "Error adding comment to PR"
fi
fi
2 changes: 2 additions & 0 deletions terraform/comment_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
'<summary>View Terraform Plan</summary>\n\n'
'```terraform\n'
'Output is limited to 1000 lines and may be truncated. See CircleCI for full details.\n'
'```\n'
'```diff\n'
'{plan}\n'
'```\n'
'</details>\n'
Expand Down