Skip to content

Commit

Permalink
fix: use terraform.tf files as fallback cache
Browse files Browse the repository at this point in the history
when repos don't have tf lockfiles
  • Loading branch information
tagoro9 committed Nov 26, 2024
1 parent e2754d1 commit 0470a59
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion lint/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,17 @@ runs:
run: |
echo "TF_PLUGIN_CACHE_DIR=${{ runner.temp }}/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "${{ runner.temp }}/.terraform.d/plugin-cache"
- name: Check for terraform lockfiles
id: check_terraform_lockfiles
if: inputs.s3-bucket-name != ''
uses: andstor/file-existence-action@v3
with:
files: "**/.terraform.lock.hcl"
- name: Compute terraform plugin cache key
if: inputs.s3-bucket-name != ''
id: tf_plugin_cache_key
run: |
echo "key=terraform-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}" >> $GITHUB_OUTPUT
echo "key=terraform-${{ runner.os }}-${{ steps.check_terraform_lockfiles.outputs.files_exists == 'true' && hashFiles('**/.terraform.lock.hcl') || hashFiles('**/terraform.tf') }}" >> $GITHUB_OUTPUT
shell: bash
- name: Load cached terraform plugins if available
if: inputs.s3-bucket-name != ''
Expand Down
8 changes: 7 additions & 1 deletion test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,17 @@ runs:
run: |
echo "TF_PLUGIN_CACHE_DIR=${{ runner.temp }}/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "${{ runner.temp }}.terraform.d/plugin-cache"
- name: Check for terraform lockfiles
id: check_terraform_lockfiles
if: inputs.s3-bucket-name != ''
uses: andstor/file-existence-action@v3
with:
files: "**/.terraform.lock.hcl"
- name: Compute terraform plugin cache key
if: inputs.s3-bucket-name != ''
id: tf_plugin_cache_key
run: |
echo "key=terraform-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}" >> $GITHUB_OUTPUT
echo "key=terraform-${{ runner.os }}-${{ steps.check_terraform_lockfiles.outputs.files_exists == 'true' && hashFiles('**/.terraform.lock.hcl') || hashFiles('**/terraform.tf', '**/versions.tf') }}" >> $GITHUB_OUTPUT
shell: bash
- name: Load cached terraform plugins if available
if: inputs.s3-bucket-name != ''
Expand Down

0 comments on commit 0470a59

Please sign in to comment.