Lambda Build and Deploy with Terraform¶
This example demonstrates how to deploy a lambda function using Terraform.
name: Build and Deploy
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
permissions:
id-token: write
contents: read
pull-requests: write
jobs:
test:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
build:
uses: tx-pts-dai/github-workflows/.github/workflows/lambda-nodejs.yaml@v1
with:
node_version: "20"
source_dir: src/lambda
plan:
if: github.event_name == 'pull_request'
needs: [build]
strategy:
fail-fast: false
matrix:
environment: [dev, prod]
uses: tx-pts-dai/github-workflows/.github/workflows/tf-plan.yaml@v1
with:
environment: ${{ matrix.environment }}
gh_artifact_name: artifact
apply:
if: github.ref_name == github.event.repository.default_branch && (github.event_name == 'push' || github.event_name == 'workflow_dispatch')
needs: [build]
strategy:
fail-fast: true
max-parallel: 1
matrix:
environment: [dev, prod]
uses: tx-pts-dai/github-workflows/.github/workflows/tf-apply.yaml@v1
with:
environment: ${{ matrix.environment }}
gh_artifact_name: artifact