Pulumi Infrastructure as code

Version 3.268 · source

Start here

pulumi new <template>
Create a project
pulumi preview
Show planned changes
pulumi up
Deploy the stack
pulumi stack output
Read stack outputs
pulumi config set <key> <value>
Set a config value
pulumi stack select <stack>
Switch stack
pulumi refresh
Sync state with the cloud
pulumi destroy
Tear everything down

Concepts

  1. Program code per project
  2. Engine diff vs state
  3. Stack one environment
  4. Cloud resources real infrastructure

Projects & deploys

pulumi new <template>
Create a project from a template
List templates with pulumi new --list-templates (shows locally cached ones).
pulumi new <template> --yes
Accept all defaults
pulumi new --generate-only
Scaffold only, no stack or install
pulumi preview
Show what up would change
pulumi preview --diff
Preview as a rich diff
pulumi preview --expect-no-changes
Fail if drift or changes exist
pulumi up
Preview, confirm, then deploy
pulumi up --yes
Deploy without the prompt
Use in CI; pair with --skip-preview only if a prior step already previewed.
pulumi up --skip-preview
Deploy without previewing first
pulumi up --refresh
Refresh state before deploying
pulumi up --diff
Show changes as a rich diff
pulumi up --message <text>
Attach a note to the update
pulumi up --parallel <n>
Limit concurrent operations
pulumi up --continue-on-error
Keep going after failures
pulumi destroy
Delete all resources in the stack
pulumi destroy --remove
Also remove the empty stack
pulumi destroy --preview-only
Show what would be deleted
pulumi destroy --exclude-protected
Skip protected resources
pulumi refresh
Update state from the real cloud
pulumi refresh --yes
Refresh without the prompt
pulumi watch
Redeploy on file changes

Targeting

pulumi up --target <urn>
Update only these resources
URNs accept wildcards. Use for exceptions; the rest of the stack is left as is.
pulumi up --target <urn> --target-dependents
Include dependents too
pulumi up --replace <urn>
Force recreating a resource
pulumi up --exclude <urn>
Leave these resources alone
pulumi up --target-replace <urn>
Replace one resource, touch nothing else
pulumi up --ignore-protect
Allow changing protected resources
pulumi stack --show-urns
List resources with their URNs

Stacks

pulumi stack init <name>
Create a stack
pulumi stack ls
List stacks
pulumi stack select <name>
Switch the current stack
pulumi stack
Show current stack and resources
pulumi stack output
Show all outputs
pulumi stack output <name>
Print one output value
pulumi stack output --json
Outputs as JSON
pulumi stack output --show-secrets
Reveal secret outputs
pulumi stack rm <name>
Delete an empty stack
Add --force to drop a stack that still has resources; they are not destroyed.
pulumi stack rename <new>
Rename the current stack
pulumi stack history
Show past updates
pulumi stack export > <file>
Dump the stack state as JSON
pulumi stack import --file <file>
Load a state dump
pulumi stack tag set <name> <value>
Set a stack tag
pulumi stack graph <file>
Write the dependency graph
pulumi up --stack <name>
Act on a stack without selecting it

Config & secrets

pulumi config
List config values
pulumi config set <key> <value>
Set a config value
pulumi config set --secret <key> <value>
Store a value encrypted
pulumi config get <key>
Read one value
pulumi config rm <key>
Remove a value
pulumi config set <key> --path <value>
Set a nested map/list key
Use with dotted keys such as outer.inner or list[0].
pulumi config set --type int <key> <value>
Store as bool, int or float
pulumi config get <key> --show-secrets
Decrypt a secret
pulumi up --config <key>=<value>
Override config for one run
PULUMI_CONFIG_PASSPHRASE
Unlock a passphrase secrets provider
pulumi stack change-secrets-provider <url>
Switch the secrets provider

Backends & state

pulumi login
Log in to Pulumi Cloud
Reads PULUMI_ACCESS_TOKEN if set, otherwise prompts.
pulumi login --local
Keep state on this machine
pulumi login file://<path>
Use a local directory as backend
pulumi login s3://<bucket>
Use an S3 bucket as backend
pulumi login gs://<bucket>
Use a GCS bucket as backend
pulumi login azblob://<container>
Use Azure Blob as backend
PULUMI_BACKEND_URL=<url>
Choose the backend via environment
pulumi state delete <urn>
Drop a resource from state only
The real resource is left running; add --target-dependents if others depend on it.
pulumi state rename <urn> <name>
Rename a resource in state
pulumi state unprotect <urn>
Clear a resource's protect flag
pulumi state move --source <s> --dest <d> <urn>
Move resources between stacks
pulumi state repair
Fix an invalid state file
pulumi cancel
Release a stuck update lock
pulumi whoami
Show the logged-in user and backend
pulumi logout
Log out of the backend

Import & logs

pulumi import <type> <name> <id>
Adopt an existing resource
Prints generated code to paste into your program; add the same resource there afterwards.
pulumi import --file <file>
Import many from a JSON list
pulumi import --out <file>
Write generated code to a file
pulumi import --protect=false
Do not mark imports as protected
pulumi import --preview-only
Show the import without doing it
pulumi logs
Show recent resource logs
pulumi logs --follow
Stream logs live
pulumi logs --since <duration>
Limit to recent logs
pulumi logs --resource <name>
Filter to one resource

Global flags

--cwd <dir>
Run as if started in <dir>
--non-interactive
Never prompt
--json
Machine-readable output
Supported by up, preview, destroy, import and stack output; not by every command.
--color never
Disable colour
--verbose <n>
Raise log verbosity
Combine with --logtostderr to see logs on the terminal.
--logtostderr
Send logs to stderr
--show-secrets
Print secret values

Recipes

First deployment
pulumi new aws-typescriptpulumi config set aws:region eu-central-1pulumi previewpulumi uppulumi stack output
Add a prod stack
pulumi stack init prodpulumi config set --secret dbPassword <pw>pulumi up --stack prod
Self-managed state in S3
export PULUMI_CONFIG_PASSPHRASE=<pass>pulumi login s3://<bucket>pulumi stack init devpulumi up --yes
Adopt an existing resource
pulumi import aws:s3/bucket:Bucket my-bucket <bucket-name># paste the generated code into the programpulumi preview   # expect no changes
CI deploy
pulumi loginpulumi stack select <org>/<project>/prodpulumi preview --non-interactivepulumi up --yes --non-interactive