Skip to content

Terraform Stack with Multiple Releases

This example demonstrates how to deploy multiple Terraform stacks with different releases and environments.

The matrix will produce the following jobs:

  • platform-v0-dev
  • platform-v0-prod
  • platform-v1-dev
  • platform-v1-prod

A common use case for creating a new stack release is to provide a way to deploy a new version of the stack without affecting the existing stack. This is useful for testing new features or changes before deploying to production.

name: Deployment

on:
  push:
    branches: [main]
    paths:
      - platform/**
  pull_request:
    branches: [main]
    paths:
      - platform/**
  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: [platform]
        deployment: [v0, v1]
        environment: [dev, prod]
    uses: tx-pts-dai/github-workflows/.github/workflows/tf-plan.yaml@v1
    with:
      environment: ${{ matrix.stack }}-${{ matrix.deployment}}-${{ matrix.environment }}

  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: [platform]
        deployment: [v0, v1]
        environment: [dev, prod]
    uses: tx-pts-dai/github-workflows/.github/workflows/tf-apply.yaml@v1
    with:
      environment: ${{ matrix.stack }}-${{ matrix.deployment}}-${{ matrix.environment }}