|
| 1 | +name: "π Apply Staging" |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: [main] |
| 6 | + paths: |
| 7 | + - "staging/**" |
| 8 | + - "template/**" |
| 9 | + - ".github/workflows/apply-staging.yml" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +# Stateless runs must never overlap: each one imports existing buckets into |
| 13 | +# a fresh throwaway state, so two racing applies would double-create. |
| 14 | +concurrency: |
| 15 | + group: terraform-staging |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +permissions: |
| 19 | + contents: read |
| 20 | + |
| 21 | +env: |
| 22 | + CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} |
| 23 | + TF_VAR_cloudflare_account_id: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} |
| 24 | + TF_IN_AUTOMATION: "true" |
| 25 | + # Lets mise query the GitHub releases API without anonymous rate limits |
| 26 | + GITHUB_TOKEN: ${{ github.token }} |
| 27 | + |
| 28 | +jobs: |
| 29 | + plan: |
| 30 | + name: "π Terraform Plan" |
| 31 | + runs-on: ubuntu-latest |
| 32 | + defaults: |
| 33 | + run: |
| 34 | + working-directory: "staging" |
| 35 | + steps: |
| 36 | + - name: "π Checkout" |
| 37 | + uses: actions/checkout@v7 |
| 38 | + |
| 39 | + - name: "π Setup mise" |
| 40 | + uses: jdx/mise-action@v4 |
| 41 | + |
| 42 | + - name: "π¨ Format Check" |
| 43 | + working-directory: "." |
| 44 | + run: terraform fmt -check -recursive staging template |
| 45 | + |
| 46 | + - name: "βοΈ Terraform Init" |
| 47 | + run: terraform init -input=false |
| 48 | + |
| 49 | + - name: "β
Terraform Validate" |
| 50 | + run: terraform validate |
| 51 | + |
| 52 | + - name: "π₯ Import Existing Buckets" |
| 53 | + run: ../scripts/import-resources.sh |
| 54 | + |
| 55 | + - name: "π Terraform Plan" |
| 56 | + run: terraform plan -input=false -out=tfplan |
| 57 | + |
| 58 | + - name: "π¦ Upload Plan" |
| 59 | + uses: actions/upload-artifact@v4 |
| 60 | + with: |
| 61 | + name: tfplan |
| 62 | + path: | |
| 63 | + staging/tfplan |
| 64 | + staging/terraform.tfstate |
| 65 | + retention-days: 3 |
| 66 | + if-no-files-found: warn |
| 67 | + |
| 68 | + apply: |
| 69 | + name: "π Terraform Apply" |
| 70 | + needs: plan |
| 71 | + if: github.event_name == 'workflow_dispatch' |
| 72 | + runs-on: ubuntu-latest |
| 73 | + # The environment carries a 24h wait timer (configured in repo settings): |
| 74 | + # the job sits in "Waiting" for 24h, and cancelling the run aborts the apply. |
| 75 | + environment: "Staging" |
| 76 | + defaults: |
| 77 | + run: |
| 78 | + working-directory: "staging" |
| 79 | + steps: |
| 80 | + - name: "π Checkout" |
| 81 | + uses: actions/checkout@v7 |
| 82 | + |
| 83 | + - name: "π Setup mise" |
| 84 | + uses: jdx/mise-action@v4 |
| 85 | + |
| 86 | + - name: "π¦ Download Plan" |
| 87 | + uses: actions/download-artifact@v4 |
| 88 | + with: |
| 89 | + name: tfplan |
| 90 | + path: staging |
| 91 | + |
| 92 | + - name: "βοΈ Terraform Init" |
| 93 | + run: terraform init -input=false |
| 94 | + |
| 95 | + - name: "π Terraform Apply" |
| 96 | + run: terraform apply -input=false tfplan |
0 commit comments