Skip to content

Commit

Permalink
plan out stacks individually
Browse files Browse the repository at this point in the history
  • Loading branch information
sikhlana committed Nov 8, 2024
1 parent ffc7b22 commit c245185
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
40 changes: 39 additions & 1 deletion .github/workflows/plan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,46 @@ concurrency:
cancel-in-progress: true

jobs:
stacks:
runs-on: ubuntu-latest
outputs:
stacks: ${{ steps.stacks.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup NodeJS
uses: actions/setup-node@v4
with:
node-version: 20
cache: yarn
cache-dependency-path: yarn.lock

- name: Generate Terraform Bindings
run: |
npx --yes cdktf-cli get
- name: Install NPM Dependencies
run: |
rm -rf node_modules/
yarn install --frozen-lockfile --production
- name: Load .env File Contents
env:
ENV_FILE_CONTENTS: ${{ secrets.ENV_FILE_CONTENTS }}
run: |
echo "${ENV_FILE_CONTENTS}" | tee .env
- id: stacks
name: Get Stacks
run: |
echo "matrix={stack: $(npx --yes ts-node main.ts)}" >> $GITHUB_OUTPUT
plan:
runs-on: ubuntu-latest
needs: stacks
strategy:
matrix: ${{ fromJSON(needs.stacks.outputs.stacks) }}
steps:
- name: Checkout
uses: actions/checkout@v4
Expand Down Expand Up @@ -47,5 +85,5 @@ jobs:
with:
mode: plan-only
githubToken: ${{ secrets.GITHUB_TOKEN }}
stackName: '*'
stackName: ${{ matrix.stack }}
updateComment: 'false'
13 changes: 9 additions & 4 deletions main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { container } from 'tsyringe';

process.env.BASE_DIRECTORY = __dirname;

async function main(app: App): Promise<void> {
async function main(app: App): Promise<string[]> {
// eslint-disable-next-line @typescript-eslint/no-var-requires
require('dotenv-expand').expand(require('dotenv').config());

Expand Down Expand Up @@ -146,14 +146,19 @@ async function main(app: App): Promise<void> {
if (buildTfCloudStack) {
buildTerraformCloudStack(app, stacks);
}

return Array.from(stacks.keys());
}

(async (app: App) => {
await main(app);
return app;
})(new App()).then((app) => {
const stacks = await main(app);

return { app, stacks };
})(new App()).then(({ app, stacks }) => {
if (process.env.CDKTF_OUTDIR) {
app.synth();
} else if (process.env.CI) {
process.stdout.write(`${JSON.stringify(stacks)}\n`, 'utf-8');
} else {
printTree(
app,
Expand Down

0 comments on commit c245185

Please sign in to comment.