@wanews/nx-pulumi
TypeScript icon, indicating that this package has built-in type declarations

0.27.0 • Public • Published

@wanews/nx-pulumi

NX Plugin for setting up Pulumi projects in an NX repo.

Generators

init

nx g @wanews/nx-pulumi:init

create-stack

nx g @wanews/nx-pulumi:create-stack --projectName=my-app-infrastructure --env=dev

env

--env=prod

Will create the stack name by prefixing the pulumi project name. ie --env=prod is the same as --stack=<projectname>.prod.

destroy-stack

nx g @wanews/nx-pulumi:destroy-stack --projectName=my-app-infrastructure --env=dev

env

--env=prod

Will create the stack name by prefixing the pulumi project name. ie --env=prod is the same as --stack=<projectname>.prod.

config-backup

Config files have the secret provider hashes so as an alternative to checking them into git you can use this command to put the config files into s3, then optionally restore them before doing an up

If you use this feature you will need to install @aws-sdk/client-s3

nx g @wanews/nx-pulumi:backup-config --projectName=my-app-infrastructure --env=dev

config-restore

Config files have the secret provider hashes so as an alternative to checking them into git you can use this command to put the config files into s3, then optionally restore them before doing an up

nx g @wanews/nx-pulumi:restore-config --projectName=my-app-infrastructure --env=dev

Executors

up

nx up my-app-infrastructure --stack dev

env

--env=prod

Will create the stack name by prefixing the pulumi project name. ie --env=prod is the same as --stack=<projectname>.prod.

Environment Variables

--envVars="KEY=value

Passes through a comma-seperated list of environment variables to the pulumi command

For example, if you need to build docker images built by pulumi to target a specific architechure CPU architechure (eg linux/amd64), you can the add arguement --envVars="DOCKER_DEFAULT_PLATFORM=linux/amd64"

Running deploy

@wanews/nx-pulumi will add a deploy target to the selected project. This will start pulumi with a --cwd of the infrastructure project automatically

All arguments will be passed onto the pulumi CLI.

Under the hood, this will run the up against your infrastructure project. You can also run the up target against the infrastructure project

nx up my-app-infrastructure --stack dev

Affected deploys

when using S3 or another state which doesn't include the project name in the state path, a good workaround is naming your stacks <project-name>.<env>. For example my-project.prod.

[projectName].[env]

For example if your name key in Pulumi.yaml is my-infrastructure and you pass --env prod, the stack name will be my-infrastructure.prod

This allows you to use the NX affected command with Pulumi to deploy all the affected stacks.

Configuration

Use the configurationStackFormat executor configuration value to change the stack name format.

Current placeholders [projectName], [environment]

Default:

configurationStackFormat='[projectName].[environment]'

Example

nx affected --target=up --env=prod --all
# Or in parallel
nx affected --target=up --env=prod --all --parallel --maxParallel=5

Running other pulumi commands

The main reason for having a plugin is to automatically build the target application and allows NX to deploy applications which have changed in the mono repo. Only the up command needs to rebuild the target application.

All other commands you can just use the --cwd apps/<my-app>-infrastructure flag when running the pulumi CLI

Troubleshooting

Error: unknown flag: --nonInteractive (or similar)

NX Mangles command line args, the issue is being tracked at https://github.com/nrwl/nx/issues/5710

This package manually reverts the mangled command line args but the list of fixed commands is not up to date. Submit a pull request adding the mapped command to libs/pulumi/src/helpers/get-pulumi-args.ts

Readme

Keywords

none

Package Sidebar

Install

npm i @wanews/nx-pulumi

Weekly Downloads

944

Version

0.27.0

License

MIT

Unpacked Size

207 kB

Total Files

88

Last publish

Collaborators

  • wimomisterx
  • karibarnard
  • jakeginnivan