Skip to content

Commit 86bfa73

Browse files
jamengualclaude
andauthored
Add skip-plandiff option and fix workspace variable usage (#89)
* Replace github.workspace with GITHUB_WORKSPACE ${{ github.workspace }} is evaluated at workflow parse time, not runtime, so it always resolves to /home/runner/_work/repo/repo regardless of where it's actually mounted in the container. * Update action.yml * Update action.yml * Add conditional check for Atmos version installation * Add skip-plandiff input to bypass plan validation This commit introduces a new `skip-plandiff` input parameter that allows users to skip the plan diff validation step and proceed directly to terraform apply. Changes: - Add `skip-plandiff` input parameter (default: 'false') - Update "Plan prepare" step to skip when skip-plandiff is enabled - Update all dependent steps (Infracost, Apply) to pass when skip-plandiff is true - Ensure Terraform Apply step runs when plan validation is skipped Use case: This is useful when you want to force an apply operation without waiting for or validating plan changes, such as in emergency deployments or when plan diff validation is not required. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix plan file selection to support skip-plandiff option This commit fixes an issue where steps would fail when skip-plandiff is enabled because they referenced a plan file that was never created. Problem: - When skip-plandiff is true, the "Plan prepare" step doesn't run - The renewed_plan_file is never created - Subsequent steps (Convert PLANFILE to JSON, Terraform Apply) failed trying to reference the non-existent renewed_plan_file Solution: - Add "Determine Plan File" step that conditionally sets the plan file: * If skip-plandiff is true: use retrieved_plan_file (from storage) * If skip-plandiff is false: use renewed_plan_file (from plan prepare) - Update "Convert PLANFILE to JSON" to use dynamic plan file - Update "Terraform Apply" to use dynamic plan filename This ensures plan-diff still works as expected while also supporting the skip-plandiff option for emergency deployments. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Matching plan action cache * Fix Debug on infracost condition * Fix Debug on infracost condition * Make --skip-init conditional based on skip-plandiff Problem: - When skip-plandiff is true, the "Plan prepare" step doesn't run - This means terraform init never executes - But the deploy command was always using --skip-init - This caused "Error: Backend initialization required" failures Solution: - Only add --skip-init flag when plan-diff actually ran - When skip-plandiff is true, allow init to run during deploy - Set SKIP_INIT_FLAG conditionally based on skip-plandiff input Also removed debug line that was accidentally left in the code. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix skip-init when skip-diff is enable and deleting unused base_cmd variable in apply step * Fix skip-init when skip-diff is enable and deleting unused base_cmd variable in apply step * Fix cache key additional ./ on dir --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 1127e95 commit 86bfa73

1 file changed

Lines changed: 48 additions & 24 deletions

File tree

action.yml

Lines changed: 48 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ inputs:
5151
description: "Enable plan storage. Default: 'true'. Set to 'false' to disable plan storage."
5252
required: false
5353
default: 'true'
54+
skip-plandiff:
55+
description: "Skip plan diff validation. Default: 'false'. Set to 'true' to skip plan prepare and diff validation."
56+
required: false
57+
default: 'false'
5458
identity:
5559
description: Atmos auth identity
5660
required: false
@@ -78,6 +82,7 @@ runs:
7882
echo "ATMOS_CLI_CONFIG_PATH=$(realpath ${{ inputs.atmos-config-path }})" >> $GITHUB_ENV
7983
8084
- name: Install Atmos
85+
if: ${{ inputs.atmos-version != '' }}
8186
uses: cloudposse/github-action-setup-atmos@v2
8287
with:
8388
atmos-version: ${{ inputs.atmos-version }}
@@ -342,7 +347,7 @@ runs:
342347
key: ${{ steps.vars.outputs.cache-key }}
343348

344349
- name: Plan prepare
345-
if: env.ACTIONS_ENABLED == 'true'
350+
if: env.ACTIONS_ENABLED == 'true' && inputs.skip-plandiff != 'true'
346351
id: plan-diff
347352
shell: bash
348353
run: |
@@ -368,7 +373,7 @@ runs:
368373
-var "job:${{ github.job }}" \
369374
-var "logoImage:${{ inputs.branding-logo-image }}" \
370375
-var "logoUrl:${{ inputs.branding-logo-url }}" \
371-
--output "${{ github.workspace }}/atmos-plan-summary.md" \
376+
--output "${GITHUB_WORKSPACE}/atmos-plan-summary.md" \
372377
--log-level $([[ "${{ inputs.debug }}" == "true" ]] && echo "DEBUG" || echo "INFO") \
373378
apply -- \
374379
atmos terraform plan ${{ inputs.component }} \
@@ -384,7 +389,7 @@ runs:
384389
cat ${TERRAFORM_PLAN_OUTPUT_FILE}
385390
386391
if [[ "${PLAN_CHANGED}" != "0" ]]; then
387-
mv ${{ github.workspace }}/atmos-plan-summary.md ${{ github.workspace }}/atmos-apply-summary.md
392+
mv ${GITHUB_WORKSPACE}/atmos-plan-summary.md ${GITHUB_WORKSPACE}/atmos-apply-summary.md
388393
cat ./atmos-apply-summary.md >> $GITHUB_STEP_SUMMARY
389394
exit 1
390395
fi
@@ -420,10 +425,23 @@ runs:
420425
exit 1
421426
fi
422427
423-
428+
- name: Determine Plan File
429+
if: env.ACTIONS_ENABLED == 'true'
430+
id: plan-file
431+
shell: bash
432+
run: |
433+
if [[ "${{ inputs.skip-plandiff }}" == "true" ]]; then
434+
# When skipping plan-diff, use the retrieved plan file
435+
echo "plan_file=${{ steps.vars.outputs.retrieved_plan_file }}" >> $GITHUB_OUTPUT
436+
echo "plan_filename=${{ steps.vars.outputs.retrieved_plan_filename }}" >> $GITHUB_OUTPUT
437+
else
438+
# When running plan-diff, use the renewed plan file
439+
echo "plan_file=${{ steps.vars.outputs.renewed_plan_file }}" >> $GITHUB_OUTPUT
440+
echo "plan_filename=${{ steps.vars.outputs.renewed_plan_filename }}" >> $GITHUB_OUTPUT
441+
fi
424442
425443
- name: Check Whether Infracost is Enabled
426-
if: env.ACTIONS_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
444+
if: env.ACTIONS_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
427445
shell: bash
428446
run: |
429447
if [[ "${{ fromJson(steps.atmos-settings.outputs.settings).enable-infracost }}" == "true" ]]; then
@@ -433,20 +451,20 @@ runs:
433451
fi
434452
435453
- name: Setup Infracost
436-
if: env.INFRACOST_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
454+
if: env.INFRACOST_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
437455
uses: infracost/actions/setup@v3
438456
with:
439457
api-key: ${{ inputs.infracost-api-key }}
440458

441459
- name: Convert PLANFILE to JSON
442-
if: env.INFRACOST_ENABLED == 'true' || env.DEBUG_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
460+
if: env.INFRACOST_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
443461
shell: bash
444462
working-directory: ${{ steps.vars.outputs.component_path }}
445463
run: |
446-
${{ fromJson(steps.atmos-settings.outputs.settings).command }} show -json "${{ steps.vars.outputs.renewed_plan_file }}" > "${{ steps.vars.outputs.plan_file }}.json"
464+
${{ fromJson(steps.atmos-settings.outputs.settings).command }} show -json "${{ steps.plan-file.outputs.plan_file }}" > "${{ steps.vars.outputs.plan_file }}.json"
447465
448466
- name: Generate Infracost Diff
449-
if: env.INFRACOST_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
467+
if: env.INFRACOST_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
450468
shell: bash
451469
working-directory: ${{ steps.vars.outputs.component_path }}
452470
run: |
@@ -462,7 +480,7 @@ runs:
462480
--out-file=/tmp/infracost.json
463481
464482
- name: Debug Infracost
465-
if: env.INFRACOST_ENABLED == 'true' && env.DEBUG_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
483+
if: env.INFRACOST_ENABLED == 'true' && env.DEBUG_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
466484
shell: bash
467485
working-directory: ${{ steps.vars.outputs.component_path }}
468486
run: |
@@ -471,7 +489,7 @@ runs:
471489
cat /tmp/infracost.json
472490
473491
- name: Set Infracost Variables
474-
if: env.INFRACOST_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
492+
if: env.INFRACOST_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
475493
id: infracost-diff
476494
working-directory: ${{ steps.vars.outputs.component_path }}
477495
shell: bash
@@ -488,17 +506,23 @@ runs:
488506
echo "infracost_diff_total_monthly_cost=$INFRACOST_DIFF_TOTAL_MONTHLY_COST" >> "$GITHUB_OUTPUT"
489507
490508
- name: Terraform Apply
491-
if: env.ACTIONS_ENABLED == 'true' && steps.plan-diff.outputs.plan_changed == 'false'
509+
if: env.ACTIONS_ENABLED == 'true' && (inputs.skip-plandiff == 'true' || steps.plan-diff.outputs.plan_changed == 'false')
492510
id: apply
493511
shell: bash
494512
run: |
495513
set +e
496514
497515
# Remove the environment file from the cache to avoid conflicts with workspace select
498-
rm -f ./.terraform/environment
499-
516+
rm -f ./.terraform/environment
517+
500518
TERRAFORM_OUTPUT_FILE="./terraform-${GITHUB_RUN_ID}-output.txt"
501519
520+
# Only skip init if plan-diff ran (which already did init)
521+
SKIP_INIT_FLAG=""
522+
if [[ "${{ inputs.skip-plandiff }}" != "true" ]]; then
523+
SKIP_INIT_FLAG="--skip-init"
524+
fi
525+
502526
tfcmt \
503527
--config "${GITHUB_ACTION_PATH}/config/atmos_github_summary.yaml" \
504528
-var "target:${{ inputs.stack }}-${{ inputs.component }}" \
@@ -509,16 +533,16 @@ runs:
509533
-var "infracost_total_monthly_cost:${{ steps.infracost-diff.outputs.infracost_diff_total_monthly_cost }}" \
510534
-var "logoImage:${{ inputs.branding-logo-image }}" \
511535
-var "logoUrl:${{ inputs.branding-logo-url }}" \
512-
--output "${{ github.workspace }}/atmos-apply-summary.md" \
536+
--output "${GITHUB_WORKSPACE}/atmos-apply-summary.md" \
513537
--log-level $([[ "${{ inputs.debug }}" == "true" ]] && echo "DEBUG" || echo "INFO") \
514538
apply -- \
515539
atmos terraform deploy ${{ inputs.component }} \
516540
--stack ${{ inputs.stack }} \
517541
${base_cmd} \
518542
-input=false \
519543
-no-color \
520-
--planfile ${{ steps.vars.outputs.renewed_plan_filename }} \
521-
--skip-init \
544+
--planfile ${{ steps.plan-file.outputs.plan_filename }} \
545+
${SKIP_INIT_FLAG} \
522546
&> ${TERRAFORM_OUTPUT_FILE}
523547
524548
TERRAFORM_RESULT=$?
@@ -535,15 +559,15 @@ runs:
535559
grep -v 'WARN detected' 1> ${{ steps.vars.outputs.component_path }}/output_values.json
536560
537561
cd ${{ steps.vars.outputs.component_path }}
538-
terraform-docs -c ${GITHUB_ACTION_PATH}/config/tfdocs-config.yaml --output-file ${{ github.workspace }}/atmos-apply-summary.md ./
562+
terraform-docs -c ${GITHUB_ACTION_PATH}/config/tfdocs-config.yaml --output-file ${GITHUB_WORKSPACE}/atmos-apply-summary.md ./
539563
cd -
540564
541-
sed -i "s#\`<sensitive>\`#![Sensitive](https://img.shields.io/badge/sensitive-c40000?style=for-the-badge)#g" ${{ github.workspace }}/atmos-apply-summary.md
542-
sed -i "s#\`\"#\`#g" ${{ github.workspace }}/atmos-apply-summary.md
543-
sed -i "s#\"\`#\`#g" ${{ github.workspace }}/atmos-apply-summary.md
544-
sed -i "s#|--#|:-#g" ${{ github.workspace }}/atmos-apply-summary.md
565+
sed -i "s#\`<sensitive>\`#![Sensitive](https://img.shields.io/badge/sensitive-c40000?style=for-the-badge)#g" ${GITHUB_WORKSPACE}/atmos-apply-summary.md
566+
sed -i "s#\`\"#\`#g" ${GITHUB_WORKSPACE}/atmos-apply-summary.md
567+
sed -i "s#\"\`#\`#g" ${GITHUB_WORKSPACE}/atmos-apply-summary.md
568+
sed -i "s#|--#|:-#g" ${GITHUB_WORKSPACE}/atmos-apply-summary.md
545569
546-
cat "${{ github.workspace }}/atmos-apply-summary.md" >> $GITHUB_STEP_SUMMARY
570+
cat "${GITHUB_WORKSPACE}/atmos-apply-summary.md" >> $GITHUB_STEP_SUMMARY
547571
548572
if [[ "${TERRAFORM_RESULT}" == "0" ]]; then
549573
echo "status=succeeded" >> $GITHUB_OUTPUT
@@ -554,7 +578,7 @@ runs:
554578
fi
555579
556580
# Link to a job that executed this action
557-
echo "[Job](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> "${{ github.workspace }}/atmos-apply-summary.md"
581+
echo "[Job](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }})" >> "${GITHUB_WORKSPACE}/atmos-apply-summary.md"
558582
559583
rm -f ${TERRAFORM_OUTPUT_FILE}
560584

0 commit comments

Comments
 (0)