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 15, 2024
1 parent aaeed94 commit 20099b8
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions lint/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,32 @@ 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 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
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.tf_plugin_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
30 changes: 30 additions & 0 deletions test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ inputs:
aws-secret-access-key:
required: false
description: Secret access key that grants access to AWS services. Requires aws-access-key-id input as well.
s3-bucket-name:
required: false
description: S3 bucket name to cache dependencies to speed up runs.
s3-bucket-region:
required: false
description: S3 bucket region to cache dependencies to speed up runs.

runs:
using: composite
Expand All @@ -39,6 +45,30 @@ 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: 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
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.tf_plugin_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: Setup
shell: bash
run: ./script/setup
Expand Down

0 comments on commit 20099b8

Please sign in to comment.