From ba5f3704d41e5393e3afe1f14f32b83898142618 Mon Sep 17 00:00:00 2001 From: ben Date: Thu, 6 Jun 2024 22:00:05 +0100 Subject: [PATCH] Use caching instead of artifacts to store .terraform (#2) Co-authored-by: Ben Martin Reviewed-on: https://git.brmartin.co.uk/ben/cluster-state/pulls/2 --- .gitea/workflows/plan-and-apply.yaml | 23 ++++++++++++++--------- modules/dummy/main.tf | 2 +- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/.gitea/workflows/plan-and-apply.yaml b/.gitea/workflows/plan-and-apply.yaml index 3ee2e69..d0ed11d 100644 --- a/.gitea/workflows/plan-and-apply.yaml +++ b/.gitea/workflows/plan-and-apply.yaml @@ -15,6 +15,7 @@ env: TF_IN_AUTOMATION: true TF_CLI_ARGS: "-no-color" PG_CONN_STR: "${{ secrets.PG_CONN_STR }}" + TF_PLUGIN_CACHE_DIR: ${{ gitea.workspace }}/.terraform.d/plugin-cache jobs: plan: @@ -22,9 +23,15 @@ jobs: steps: - uses: actions/checkout@v4 - uses: hashicorp/setup-terraform@v3 + - name: Create Terraform Plugin Cache Dir + run: mkdir -v -p $TF_PLUGIN_CACHE_DIR + - uses: actions/cache@v4 + with: + path: ${{ env.TF_PLUGIN_CACHE_DIR }} + key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} - name: Terraform fmt id: fmt - run: terraform fmt -check + run: terraform fmt -recursive -check continue-on-error: true - name: Terraform Init id: init @@ -92,10 +99,6 @@ jobs: with: name: tfplan path: tfplan - - uses: actions/upload-artifact@v3 - with: - name: .terraform - path: .terraform apply: runs-on: ubuntu-latest needs: plan @@ -103,13 +106,15 @@ jobs: steps: - uses: actions/checkout@v4 - uses: hashicorp/setup-terraform@v3 + - name: Create Terraform Plugin Cache Dir + run: mkdir -v -p $TF_PLUGIN_CACHE_DIR + - uses: actions/cache@v4 + with: + path: ${{ env.TF_PLUGIN_CACHE_DIR }} + key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} - uses: actions/download-artifact@v3 with: name: tfplan - - uses: actions/download-artifact@v3 - with: - name: .terraform - path: .terraform - name: Ensure providers are executable run: chmod -Rv +x .terraform/providers - name: Terraform apply diff --git a/modules/dummy/main.tf b/modules/dummy/main.tf index 9fdcc29..8cd9998 100644 --- a/modules/dummy/main.tf +++ b/modules/dummy/main.tf @@ -1,4 +1,4 @@ resource "nomad_job" "dummy" { jobspec = file("${path.module}/jobspec.json") - json = true + json = true } \ No newline at end of file