Skip to content

Commit

Permalink
feat(lint): add caching layer to terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
yohanb committed Nov 14, 2024
1 parent aaeed94 commit ae20461
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
27 changes: 27 additions & 0 deletions lint/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,33 @@ runs:
- name: Setup tools
# Provide opportunity to install terraform, golang, and others
uses: open-turo/action-setup-tools@v2

- name: Configure Terraform plugin cache
shell: bash
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Compute pre-commit cache key
if: inputs.s3-bucket-name != ''
id: pre_commit_cache_key
run: |
echo "key=${{ hashFiles('**/.pre-commit-config.yaml') }}" >> $GITHUB_OUTPUT
shell: bash
- name: Load cached terraform plugins if available
if: inputs.s3-bucket-name != ''
uses: everpcpc/actions-cache@v2
id: read_cache
with:
bucket: ${{ inputs.s3-bucket-name }}
use-fallback: false
path: ~/.terraform.d/plugin-cache
key: ${{ env.cache-name }}-${{ steps.pre_commit_cache_key.outputs.key }}
restore-keys: ${{ env.cache-name }}-
env:
AWS_REGION: ${{ inputs.s3-bucket-region }}
cache-name: ${{ github.event.repository.name }}/cache-tf-plugins

- name: Pre-commit
uses: open-turo/action-pre-commit@v3
with:
Expand Down
13 changes: 13 additions & 0 deletions test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,19 @@ runs:
run: |
if [[ ! -f ./script/setup ]]; then echo "Missing required file: ./script/setup"; exit 1; fi
if [[ ! -f ./script/test ]]; then echo "Missing required file: ./script/test"; exit 1; fi
- name: Configure Terraform plugin cache
shell: bash
run: |
echo "TF_PLUGIN_CACHE_DIR=$HOME/.terraform.d/plugin-cache" >>"$GITHUB_ENV"
mkdir --parents "$HOME/.terraform.d/plugin-cache"
- name: Cache Terraform
uses: actions/cache@v4
with:
path: |
~/.terraform.d/plugin-cache
key: terraform-${{ runner.os }}-${{ hashFiles('**/.terraform.lock.hcl') }}
restore-keys: |
terraform-${{ runner.os }}-
- name: Setup
shell: bash
run: ./script/setup
Expand Down

0 comments on commit ae20461

Please sign in to comment.