Skip to content

Commit 2280fbc

Browse files
committed
Fix -var precedence
Better logging of -var flags. Fixes diff output
1 parent fd3626f commit 2280fbc

File tree

4 files changed

+18
-8
lines changed

4 files changed

+18
-8
lines changed

.github/workflows/test-apply.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1007,6 +1007,7 @@ jobs:
10071007
- name: Apply
10081008
uses: ./terraform-apply
10091009
id: apply
1010+
continue-on-error: true
10101011
with:
10111012
label: test-apply deprecated_var_terraform_1_10
10121013
path: tests/workflows/test-apply/deprecated_var

image/actions.sh

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,14 @@ function set-deprecated-var-args() {
390390
fi
391391
}
392392

393+
function masked-deprecated-vars() {
394+
if [[ -n "$DEPRECATED_VAR_ARGS" ]]; then
395+
echo "-var <masked>"
396+
else
397+
echo ""
398+
fi
399+
}
400+
393401
function set-plan-args() {
394402
set-common-plan-args
395403
set-deprecated-var-args
@@ -474,11 +482,11 @@ function plan() {
474482
fi
475483

476484
# shellcheck disable=SC2086
477-
debug_log $TOOL_COMMAND_NAME plan -input=false -no-color -detailed-exitcode -lock-timeout=300s $PARALLEL_ARG $PLAN_OUT_ARG $PLAN_ARGS $VARIABLE_ARGS '$DEPRECATED_VAR_ARGS' # don't expand deprecated var args
485+
debug_log $TOOL_COMMAND_NAME plan -input=false -no-color -detailed-exitcode -lock-timeout=300s $PARALLEL_ARG $PLAN_OUT_ARG $PLAN_ARGS "$(masked-deprecated-vars)" $VARIABLE_ARGS
478486

479487
set +e
480488
# shellcheck disable=SC2086
481-
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME plan -input=false -no-color -detailed-exitcode -lock-timeout=300s $PARALLEL_ARG $PLAN_OUT_ARG $PLAN_ARGS $VARIABLE_ARGS $DEPRECATED_VAR_ARGS) \
489+
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME plan -input=false -no-color -detailed-exitcode -lock-timeout=300s $PARALLEL_ARG $PLAN_OUT_ARG $PLAN_ARGS $DEPRECATED_VAR_ARGS $VARIABLE_ARGS ) \
482490
2>"$STEP_TMP_DIR/terraform_plan.stderr" \
483491
| $TFMASK \
484492
| tee /dev/fd/3 "$STEP_TMP_DIR/terraform_plan.stdout" \
@@ -502,11 +510,11 @@ function plan() {
502510

503511
function destroy() {
504512
# shellcheck disable=SC2086
505-
debug_log $TOOL_COMMAND_NAME destroy -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $VARIABLE_ARGS '$DEPRECATED_VAR_ARGS' # don't expand deprecated var args
513+
debug_log $TOOL_COMMAND_NAME destroy -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS "$(masked-deprecated-vars)" $VARIABLE_ARGS
506514

507515
set +e
508516
# shellcheck disable=SC2086
509-
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME destroy -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $VARIABLE_ARGS $DEPRECATED_VAR_ARGS) \
517+
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME destroy -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $DEPRECATED_VAR_ARGS $VARIABLE_ARGS) \
510518
2>"$STEP_TMP_DIR/terraform_destroy.stderr" \
511519
| tee /dev/fd/3 \
512520
>"$STEP_TMP_DIR/terraform_destroy.stdout"

image/entrypoints/apply.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@ function apply() {
5656
# Instead we need to do an auto approved apply using the arguments we would normally use for the plan
5757

5858
# shellcheck disable=SC2086,SC2016
59-
debug_log $TOOL_COMMAND_NAME apply -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $VARIABLE_ARGS '$DEPRECATED_VAR_ARGS' # don't expand deprecated var args
59+
debug_log $TOOL_COMMAND_NAME apply -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS "$(masked-deprecated-vars)" $VARIABLE_ARGS
6060
# shellcheck disable=SC2086
61-
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME apply -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $VARIABLE_ARGS $DEPRECATED_VAR_ARGS) \
61+
(cd "$INPUT_PATH" && $TOOL_COMMAND_NAME apply -input=false -no-color -auto-approve -lock-timeout=300s $PARALLEL_ARG $PLAN_ARGS $DEPRECATED_VAR_ARGS $VARIABLE_ARGS) \
6262
2>"$STEP_TMP_DIR/terraform_apply.stderr" \
6363
| $TFMASK \
6464
| tee "$STEP_TMP_DIR/terraform_apply.stdout"

image/src/github_pr_comment/__main__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -642,8 +642,6 @@ def main() -> int:
642642

643643
debug(f'diff {proposed_plan_path} {approved_plan_path}')
644644
diff_complete = subprocess.run(['diff', proposed_plan_path, approved_plan_path], check=False, capture_output=True, encoding='utf-8')
645-
sys.stdout.write(diff_complete.stdout)
646-
sys.stderr.write(diff_complete.stderr)
647645

648646
if diff_complete.returncode != 0:
649647
sys.stdout.write("""Performing diff between the pull request plan and the plan generated at execution time.
@@ -652,6 +650,9 @@ def main() -> int:
652650
Plan differences:
653651
""")
654652

653+
sys.stdout.write(diff_complete.stdout)
654+
sys.stderr.write(diff_complete.stderr)
655+
655656
if comment.headers.get('plan_text_format', 'text').endswith('trunc'):
656657
sys.stdout.write('\nThe plan text was too large for a PR comment, not all differences may be shown here.')
657658

0 commit comments

Comments
 (0)