Skip to content

Commit

Permalink
fix(terraform): cache not restored in Apply job (#627)
Browse files Browse the repository at this point in the history
The `Terraform Apply` job does not restore cache if the `Terraform Plan` job does not save cache. This causes an error in scenarios where cache already exists, and it'll only be restored in the `Terraform Plan` job but not the `Terraform Apply` job.
  • Loading branch information
hknutsen authored Jan 7, 2025
1 parent 96604cc commit a6ffd90
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ jobs:
artifact-id: ${{ steps.upload.outputs.artifact-id }}
plugin-cache-dir: ${{ steps.mkdir.outputs.plugin-cache-dir }}
cache-primary-key: ${{ steps.cache-restore.outputs.cache-primary-key }}
cache-restore-hit: ${{ steps.cache-restore.outputs.cache-hit }}
cache-save-outcome: ${{ steps.cache-save.outcome }}

terraform-apply:
Expand Down Expand Up @@ -298,7 +299,7 @@ jobs:
path: ${{ inputs.working_directory }}

- name: Restore cache
if: needs.terraform-plan.outputs.cache-save-outcome == 'success'
if: needs.terraform-plan.outputs.cache-restore-hit == 'true' || needs.terraform-plan.outputs.cache-save-outcome == 'success'
uses: actions/cache/restore@1bd1e32a3bdc45362d1e726936510720a7c30a57
with:
path: ${{ needs.terraform-plan.outputs.plugin-cache-dir }}
Expand Down

0 comments on commit a6ffd90

Please sign in to comment.