@@ -211,6 +211,19 @@ inputs:
211211 description : " allows overriding of the terraform cache dir which defaults to ${github.workspace}/cache"
212212 required : false
213213 default : ' '
214+ cache-dependencies-s3 :
215+ description : " Use S3 for caching terraform/terragrunt dependencies"
216+ required : false
217+ default : ' false'
218+ cache-dependencies-s3-bucket :
219+ description : " S3 bucket URL for caching (e.g., s3://mybucket/cache)"
220+ required : false
221+ default : ' '
222+ cache-dependencies-s3-region :
223+ description : " AWS region for S3 cache bucket"
224+ required : false
225+ default : ' us-east-1'
226+
214227
215228 digger-spec :
216229 description : " (orchestrator only) the spec to pass onto digger cli"
@@ -316,6 +329,24 @@ runs:
316329 digger-cache
317330 if : ${{ inputs.cache-dependencies == 'true' }}
318331
332+ - name : restore-s3-cache
333+ shell : bash
334+ run : |
335+ BUCKET=$(echo "${{ inputs.cache-dependencies-s3-bucket }}" | sed 's|^s3://||')
336+ REGION="${{ inputs.cache-dependencies-s3-region }}"
337+
338+ SCRIPT_PATH="${{ github.action_path }}/scripts/s3-cache-download.bash"
339+ if [ ! -f "$SCRIPT_PATH" ]; then
340+ echo "::error::S3 cache download script not found at $SCRIPT_PATH"
341+ echo "Please make sure the script exists and is properly installed."
342+ exit 1
343+ fi
344+
345+ chmod +x "$SCRIPT_PATH"
346+ "$SCRIPT_PATH" "$BUCKET" "$REGION" "$TF_PLUGIN_CACHE_DIR"
347+ if : ${{ inputs.cache-dependencies-s3 == 'true' }}
348+
349+ # Then terraform setup happens...
319350 - name : Setup Terraform
320351 uses : hashicorp/setup-terraform@v3
321352 with :
@@ -429,8 +460,11 @@ runs:
429460
430461 NO_BACKEND : ${{ inputs.no-backend }}
431462 DEBUG : ' true'
432- TG_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
433- TERRAGRUNT_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
463+ TG_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
464+ TERRAGRUNT_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
465+ TF_PLUGIN_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
466+ TG_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
467+ TERRAGRUNT_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
434468 DIGGER_RUN_SPEC : ${{inputs.digger-spec}}
435469 run : |
436470 if [[ ${{ inputs.ee }} == "true" ]]; then
@@ -476,8 +510,11 @@ runs:
476510 INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL : ${{ inputs.drift-detection-slack-notification-url }}
477511 INPUT_DRIFT_DETECTION_ADVANCED_SLACK_NOTIFICATION_URL : ${{ inputs.drift-detection-advanced-slack-notification-url }}
478512 NO_BACKEND : ${{ inputs.no-backend }}
479- TG_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
480- TERRAGRUNT_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
513+ TG_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
514+ TERRAGRUNT_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
515+ TF_PLUGIN_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
516+ TG_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
517+ TERRAGRUNT_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
481518 DIGGER_RUN_SPEC : ${{inputs.digger-spec}}
482519 id : digger
483520 shell : bash
@@ -524,8 +561,11 @@ runs:
524561 INPUT_DRIFT_DETECTION_SLACK_NOTIFICATION_URL : ${{ inputs.drift-detection-slack-notification-url }}
525562 INPUT_DRIFT_DETECTION_ADVANCED_SLACK_NOTIFICATION_URL : ${{ inputs.drift-detection-advanced-slack-notification-url }}
526563 NO_BACKEND : ${{ inputs.no-backend }}
527- TG_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
528- TERRAGRUNT_PROVIDER_CACHE : ${{ inputs.cache-dependencies == 'true' && 1 || 0 }}
564+ TG_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
565+ TERRAGRUNT_PROVIDER_CACHE : ${{ (inputs.cache-dependencies == 'true' || inputs.cache-dependencies-s3 == 'true') && 1 || 0 }}
566+ TF_PLUGIN_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
567+ TG_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
568+ TERRAGRUNT_PROVIDER_CACHE_DIR : ${{ env.TF_PLUGIN_CACHE_DIR }}
529569 DIGGER_RUN_SPEC : ${{inputs.digger-spec}}
530570 id : digger-local-run
531571 shell : bash
@@ -567,6 +607,23 @@ runs:
567607 path : ${{ env.TF_PLUGIN_CACHE_DIR }}
568608 key : digger-cache-${{ hashFiles('**/cache') }}
569609
610+ - name : save-s3-cache
611+ shell : bash
612+ run : |
613+ BUCKET=$(echo "${{ inputs.cache-dependencies-s3-bucket }}" | sed 's|^s3://||')
614+ REGION="${{ inputs.cache-dependencies-s3-region }}"
615+
616+ SCRIPT_PATH="${{ github.action_path }}/scripts/s3-cache-upload.bash"
617+ if [ ! -f "$SCRIPT_PATH" ]; then
618+ echo "::error::S3 cache upload script not found at $SCRIPT_PATH"
619+ echo "Please make sure the script exists and is properly installed."
620+ exit 1
621+ fi
622+
623+ chmod +x "$SCRIPT_PATH"
624+ "$SCRIPT_PATH" "$BUCKET" "$REGION" "$TF_PLUGIN_CACHE_DIR"
625+ if : ${{ always() && inputs.cache-dependencies-s3 == 'true' }}
626+
570627branding :
571628 icon : globe
572629 color : purple
0 commit comments