From 11d68c467b7aa6757320376328db0bc907a933c5 Mon Sep 17 00:00:00 2001 From: motatoes Date: Mon, 20 Jan 2025 10:58:49 -0800 Subject: [PATCH 1/6] allow cache values to be overridable --- action.yml | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index b14097b1..7720ac35 100644 --- a/action.yml +++ b/action.yml @@ -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 @@ -369,9 +378,18 @@ 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 + # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' + TF_PLUGIN_CACHE_DIR: ${{ + inputs.terraform-cache-dir == '' && + format('{0}/cache', github.workspace) || + inputs.terraform-cache-dir + }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ github.workspace }}/cache + TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ + inputs.terragrunt-cache-dir == '' && + format('{0}/cache', github.workspace) || + inputs.terragrunt-cache-dir + }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} run: | if [[ ${{ inputs.ee }} == "true" ]]; then @@ -407,9 +425,19 @@ 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 + # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' + TF_PLUGIN_CACHE_DIR: ${{ + inputs.terraform-cache-dir == '' && + format('{0}/cache', github.workspace) || + inputs.terraform-cache-dir + }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ github.workspace }}/cache + # if terragrunt-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' + TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ + inputs.terragrunt-cache-dir == '' && + format('{0}/cache', github.workspace) || + inputs.terragrunt-cache-dir + }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} id: digger shell: bash From 814b10548a964b6ff8f0355b697820d22d725e79 Mon Sep 17 00:00:00 2001 From: motatoes Date: Mon, 20 Jan 2025 12:37:06 -0800 Subject: [PATCH 2/6] fix action format --- action.yml | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/action.yml b/action.yml index 7720ac35..efe5bc55 100644 --- a/action.yml +++ b/action.yml @@ -379,17 +379,13 @@ runs: NO_BACKEND: ${{ inputs.no-backend }} DEBUG: 'true' # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TF_PLUGIN_CACHE_DIR: ${{ - inputs.terraform-cache-dir == '' && + TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && format('{0}/cache', github.workspace) || - inputs.terraform-cache-dir - }} + inputs.terraform-cache-dir }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ - inputs.terragrunt-cache-dir == '' && + TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ inputs.terragrunt-cache-dir == '' && format('{0}/cache', github.workspace) || - inputs.terragrunt-cache-dir - }} + inputs.terragrunt-cache-dir }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} run: | if [[ ${{ inputs.ee }} == "true" ]]; then @@ -426,18 +422,14 @@ runs: INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }} NO_BACKEND: ${{ inputs.no-backend }} # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TF_PLUGIN_CACHE_DIR: ${{ - inputs.terraform-cache-dir == '' && + TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && format('{0}/cache', github.workspace) || - inputs.terraform-cache-dir - }} + inputs.terraform-cache-dir }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} # if terragrunt-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ - inputs.terragrunt-cache-dir == '' && + TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ inputs.terragrunt-cache-dir == '' && format('{0}/cache', github.workspace) || - inputs.terragrunt-cache-dir - }} + inputs.terragrunt-cache-dir }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} id: digger shell: bash From a0c734fdd4c31dc3a0638950d9f55bf7ba82d230 Mon Sep 17 00:00:00 2001 From: motatoes Date: Mon, 20 Jan 2025 13:03:01 -0800 Subject: [PATCH 3/6] refactor out variable setting --- action.yml | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) diff --git a/action.yml b/action.yml index efe5bc55..9ea6d5f7 100644 --- a/action.yml +++ b/action.yml @@ -256,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 @@ -355,6 +365,7 @@ runs: mkdir -p $GITHUB_WORKSPACE/cache shell: bash + - name: build and run digger if: ${{ !startsWith(github.action_ref, 'v') }} shell: bash @@ -378,14 +389,7 @@ runs: INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL: ${{ inputs.drift-detection-slack-notification-url }} NO_BACKEND: ${{ inputs.no-backend }} DEBUG: 'true' - # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && - format('{0}/cache', github.workspace) || - inputs.terraform-cache-dir }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ inputs.terragrunt-cache-dir == '' && - format('{0}/cache', github.workspace) || - inputs.terragrunt-cache-dir }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} run: | if [[ ${{ inputs.ee }} == "true" ]]; then @@ -421,15 +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 }} - # if terraform-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TF_PLUGIN_CACHE_DIR: ${{ inputs.terraform-cache-dir == '' && - format('{0}/cache', github.workspace) || - inputs.terraform-cache-dir }} TERRAGRUNT_PROVIDER_CACHE: ${{ inputs.cache-dependencies == 'true' && 1 || 0 }} - # if terragrunt-cache-dir is set then we set it to that otherwise set it to '${{github.workspace}}/cache' - TERRAGRUNT_PROVIDER_CACHE_DIR: ${{ inputs.terragrunt-cache-dir == '' && - format('{0}/cache', github.workspace) || - inputs.terragrunt-cache-dir }} DIGGER_RUN_SPEC: ${{inputs.digger-spec}} id: digger shell: bash @@ -448,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: From c9cf88ec23c154dedaf793e4823c73b42ca218fb Mon Sep 17 00:00:00 2001 From: Mohamed Habib Date: Mon, 20 Jan 2025 13:17:14 -0800 Subject: [PATCH 4/6] Update libs_test.yml --- .github/workflows/libs_test.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/libs_test.yml b/.github/workflows/libs_test.yml index 9c65457d..f9e83f4c 100644 --- a/.github/workflows/libs_test.yml +++ b/.github/workflows/libs_test.yml @@ -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 From e51814b84a2678136fdfa4998698f66f356d4e67 Mon Sep 17 00:00:00 2001 From: motatoes Date: Tue, 4 Feb 2025 02:30:53 -0800 Subject: [PATCH 5/6] remove terragrunt-cache input --- action.yml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/action.yml b/action.yml index 9ea6d5f7..9219a513 100644 --- a/action.yml +++ b/action.yml @@ -171,10 +171,6 @@ inputs: 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" From e2de5220f8b9a979f26dc5407f60a280c03ed5c1 Mon Sep 17 00:00:00 2001 From: motatoes Date: Tue, 4 Feb 2025 02:36:47 -0800 Subject: [PATCH 6/6] add informational message about cache --- cli/pkg/digger/digger.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/cli/pkg/digger/digger.go b/cli/pkg/digger/digger.go index ed309033..b097319b 100644 --- a/cli/pkg/digger/digger.go +++ b/cli/pkg/digger/digger.go @@ -65,9 +65,11 @@ func DetectCI() CIName { } func RunJobs(jobs []orchestrator.Job, prService ci.PullRequestService, orgService ci.OrgService, lock locking2.Lock, reporter reporting.Reporter, planStorage storage.PlanStorage, policyChecker policy.Checker, commentUpdater comment_updater.CommentUpdater, backendApi backendapi.Api, jobId string, reportFinalStatusToBackend bool, reportTerraformOutput bool, prCommentId string, workingDir string) (bool, bool, error) { - defer reporter.Flush() + log.Printf("Info: [TF_PLUGIN_CACHE_DIR=%v] ", os.Getenv("TF_PLUGIN_CACHE_DIR")) + log.Printf("Info: [TERRAGRUNT_PROVIDER_CACHE_DIR=%v", os.Getenv("TERRAGRUNT_PROVIDER_CACHE_DIR")) + runStartedAt := time.Now() exectorResults := make([]execution.DiggerExecutorResult, len(jobs))