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 diff --git a/action.yml b/action.yml index b14097b1..9219a513 100644 --- a/action.yml +++ b/action.yml @@ -167,6 +167,11 @@ 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: '' + digger-spec: description: "(orchestrator only) the spec to pass onto digger cli" required: false @@ -247,11 +252,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 @@ -346,6 +361,7 @@ runs: mkdir -p $GITHUB_WORKSPACE/cache shell: bash + - name: build and run digger if: ${{ !startsWith(github.action_ref, 'v') }} shell: bash @@ -369,9 +385,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 @@ -407,9 +421,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 @@ -428,7 +440,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: 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))