The cdk-synth-and-diff action synthesizes AWS CDK templates and performs a diff against the base branch of a pull request.
This helps detect destructive or unexpected changes early.
-
node@>=24 for github action runner
-
aws-cdkmust be installed -
Install the
@shiftcode/iac-utilitiespackage (version >=1.0.0) in the root of your repository. This package provides thestage-override-to-pr-baseandaws-env-varscommands used by the action. -
The Action assumes that the repository is configured to use AWS CDK in the provided
iacDir. Ensure that the specified directory contains a valid AWS CDK project.
| Name | Description | Required | Default Value |
|---|---|---|---|
githubToken |
GitHub token to use for the action | Yes | |
failOnDestructiveChanges |
Whether or not destructive changes should fail the job | No | true |
allowedDestroyTypes |
Comma-delimited list of resource types that are allowed to be destroyed | No | "" |
iacDir |
The location of the IAC package | No | packages/iac |
cdkOutFilename |
The name of the cdk.out file |
No | pr-base.cdk.out |
cloudFormationTemplate |
The CloudFormation template to use for the diff | No | "" |
Below is an example of how to use the cdk-synth-and-diff action in a GitHub Actions workflow:
name: Example Workflow
on:
pull_request:
branches:
- '**'
jobs:
synth-and-diff:
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- name: Install Dependencies
run: npm ci
- name: CDK synth and diff with PR base branch stage
if: github.event_name == 'pull_request'
uses: shiftcode/cdk-synth-and-diff-action@SHA # vX.Y.Z
with:
failOnDestructiveChanges: false
allowedDestroyTypes: 'AWS::ECS::TaskDefinition'
githubToken: ${{ secrets.GITHUB_TOKEN }}
cloudFormationTemplate: 'project-name-*'- Stage Override: The action uses the
stage-override-to-pr-basecommand to ensure the synthesized templates are based on the pull request's base branch. - Destructive Change Detection: The action can fail the job if destructive changes are detected, ensuring safe deployments.
- Customizable Allowed Destroy Types: Consumers can specify resource types that are allowed to be destroyed during the diff process.
The action does not produce any explicit outputs but provides diff results for the synthesized templates in form of a comment on the pull request.