Multiple Terraform Stacks¶
This example demonstrates how to deploy multiple Terraform stacks. A stack is a terraform root module.
This is a common use case for separating infrastructure and application resources.
name: Deployment
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
plan:
if: github.event_name == 'pull_request'
strategy:
fail-fast: false
matrix:
stack: [infra, app]
environment: [dev, int, prod]
uses: tx-pts-dai/github-workflows/.github/workflows/tf-plan.yaml@v1
with:
environment: ${{ matrix.stack }}-${{ matrix.environment }}
tf_dir: deploy/${{ matrix.stack }}
apply:
if: github.ref_name == github.event.repository.default_branch && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
strategy:
fail-fast: true
max-parallel: 1
matrix:
stack: [infra, app]
environment: [dev, int, prod]
uses: tx-pts-dai/github-workflows/.github/workflows/tf-apply.yaml@v1
with:
environment: ${{ matrix.stack }}-${{ matrix.environment }}
tf_dir: deploy/${{ matrix.stack }}