Skip to content

Commit

Permalink
feat(terraform): store plugins in cache (#396)
Browse files Browse the repository at this point in the history
Enable Terraform plugin cache.

Co-authored-by: Henrik Knutsen <[email protected]>
  • Loading branch information
sondresjolyst and hknutsen authored Nov 14, 2024
1 parent 97c7f84 commit 744058b
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/terraform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,22 @@ jobs:
# If the wrapper is enabled, the debug logs will be visible in the job summary.
# The wrapper must be disabled to prevent this.

- name: Create Terraform plugin cache
id: mkdir
run: |
plugin_cache_dir="$RUNNER_TEMP/.terraform.d/plugin-cache"
mkdir --parents "$plugin_cache_dir"
echo "plugin_cache_dir=$plugin_cache_dir" >> "$GITHUB_OUTPUT"
- name: Cache Terraform plugins
uses: actions/cache@6849a6489940f00c2f30c0fb92c6274307ccb58a
with:
path: ${{ steps.mkdir.outputs.plugin_cache_dir }}
key: terraform-${{ hashFiles(format('{0}/.terraform.lock.hcl', inputs.working_directory)) }}
# The dependency lock file tracks provider dependencies for the Terraform configuration in the working directory.
# Calculate a hash for the dependency lock file and use this hash to identify the plugin cache for the Terraform configuration.
# https://developer.hashicorp.com/terraform/language/files/dependency-lock

- name: Terraform Format
id: fmt
# Start Bash without fail-fast behavior.
Expand All @@ -138,6 +154,9 @@ jobs:
id: init
env:
TFBACKEND_CONFIG: ${{ inputs.backend_config }}
# Enable Terraform plugin cache.
# https://developer.hashicorp.com/terraform/cli/config/config-file#provider-plugin-cache
TF_PLUGIN_CACHE_DIR: ${{ steps.mkdir.outputs.plugin_cache_dir }}
run: |
optional_args=()
if [[ -n "$TFBACKEND_CONFIG" ]]; then
Expand Down

0 comments on commit 744058b

Please sign in to comment.