What it does
pulumi describes cloud resources with normal code: loops, functions, classes and tests. Like Terraform it keeps state, shows a preview of the changes and then applies them (up). A stack is one copy of the project (dev, staging, prod) with its own config and state.
State lives in Pulumi Cloud, or in your own backend (S3, Azure Blob, a local folder). Secrets in the config are encrypted.
How to write it
pulumi COMMAND [OPTIONS]Main parts
Commands
newTEMPLATE- Start a project (for example
azure-typescript). preview- Show what would change.
up- Create or change the resources.
destroy- Delete all resources of the stack.
stackinit|select|ls|output- Make / choose / list stacks; show outputs.
configset[--secret]KEYVALUE- Set a config value (or an encrypted secret).
refresh- Read the real state from the cloud.
importTYPENAMEID- Bring an existing resource under Pulumi.
login[URL]- Choose the state backend (
file://,s3://,azblob://). statedeleteURN- Remove a resource from the state only.
cancel- Stop a running update.
Options 8
Most used
Options
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Start a new Azure project in TypeScript
pulumi new azure-typescript -n shop-infra2Keep state in your own storage (no Pulumi Cloud)
pulumi login azblob://pulumi-state pulumi login s3://acme-pulumi-state3A small program (TypeScript)
cat index.ts import * as resources from "@pulumi/azure-native/resources"; import * as storage from "@pulumi/azure-native/storage"; const rg = new resources.ResourceGroup("rg-shop"); const sa = new storage.StorageAccount("stshop", { resourceGroupName: rg.name, kind: "StorageV2", sku: { name: "Standard_LRS" }, minimumTlsVersion: "TLS1_2", allowBlobPublicAccess: false, }); export const account = sa.name;4Preview, then apply
pulumi preview --diff pulumi up5Stacks per environment
pulumi stack init prod pulumi config set azure-native:location westeurope pulumi config set --secret dbPassword 'S3cr3t!'6Read an output
pulumi stack output account7In CI without prompts
pulumi up --stack prod --yes --non-interactive8Find drift (changes made by hand)
pulumi refresh --stack prod --yes9Bring an existing resource in
pulumi import azure-native:resources:ResourceGroup rg-old /subscriptions/SUB/resourceGroups/rg-old10Delete a test stack completely
pulumi destroy --stack dev --yes pulumi stack rm dev
Nothing matches this filter.
Watch out
destroydeletes real resources. Protect important ones withprotect: true.- Code can do anything — keep the program simple and reviewed like app code.
- Back up the state backend; lost state means Pulumi forgets what it made.
Files
Pulumi.yaml- Project name and runtime.
Pulumi.STACK.yaml- Config of one stack (secrets encrypted).
Tips to remember
- Terraform and OpenTofu have more jobs and examples; Pulumi is popular in teams of developers.
Exit codes
0 | OK. |
255 | Error. |