Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow cache values to be overridable for terraform and terragrunt #1873

Merged
merged 7 commits into from
Feb 4, 2025
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/libs_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ jobs:
uses: opentofu/setup-opentofu@v1.0.4
with:
tofu_version: 1.8.5

- name: Setup terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_wrapper: false
terraform_version: "1.5.5"

- name: Download Go
uses: actions/setup-go@v5
Expand Down
28 changes: 22 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,15 @@ inputs:
description: "Leverage actions/cache to cache dependencies to speed up execution"
required: false
default: 'false'
terraform-cache-dir:
description: "allows overriding of the terraform cache dir which defaults to ${github.workspace}/cache"
required: false
default: ''
terragrunt-cache-dir:
description: "allows overriding of the terragrunt cache dir to ${github.workspace}/cache"
required: false
default: ''

digger-spec:
description: "(orchestrator only) the spec to pass onto digger cli"
required: false
Expand Down Expand Up @@ -247,11 +256,21 @@ runs:
subscription-id: ${{ inputs.azure-subscription-id }}
if: ${{ inputs.setup-azure == 'true' && inputs.azure-client-id != '' }}

# if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache'
- name: retrieve cache dir
shell: bash
run: |
CACHE_DIR=${{ inputs.terraform-cache-dir == '' &&
format('{0}/cache', github.workspace) ||
inputs.terraform-cache-dir }}
echo "TF_PLUGIN_CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV
echo "TERRAGRUNT_PROVIDER_CACHE_DIR=$CACHE_DIR" >> $GITHUB_ENV

- uses: actions/cache/restore@v4
id: restore_cache
name: restore_cache
with:
path: ${{ github.workspace }}/cache
path: $TF_PLUGIN_CACHE_DIR
key: digger-cache
restore-keys: |
digger-cache
Expand Down Expand Up @@ -346,6 +365,7 @@ runs:
mkdir -p $GITHUB_WORKSPACE/cache
shell: bash


- name: build and run digger
if: ${{ !startsWith(github.action_ref, 'v') }}
shell: bash
Expand All @@ -369,9 +389,7 @@ runs:
INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }}
NO_BACKEND: ${{ inputs.no-backend }}
DEBUG: 'true'
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/cache
TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ github.workspace }}/cache
DIGGER_RUN_SPEC: ${{inputs.digger-spec}}
run: |
if [[ ${{ inputs.ee }} == "true" ]]; then
Expand Down Expand Up @@ -407,9 +425,7 @@ runs:
INPUT_DIGGER_COMMAND: ${{ inputs.command }}
INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }}
NO_BACKEND: ${{ inputs.no-backend }}
TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/cache
TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ github.workspace }}/cache
DIGGER_RUN_SPEC: ${{inputs.digger-spec}}
id: digger
shell: bash
Expand All @@ -428,7 +444,7 @@ runs:
name: cache-save
if: ${{ always() && inputs.cache-dependencies == 'true' && steps.restore_cache.outputs.cache-hit != 'true' }}
with:
path: ${{ github.workspace }}/cache
path: $TF_PLUGIN_CACHE_DIR
key: digger-cache-${{ hashFiles('**/cache') }}

branding:
Expand Down
Loading