Overview
Pulumi enables defining and managing cloud infrastructure using real programming languages (TypeScript, Python, Go, C#) instead of domain-specific languages. It supports 150+ cloud providers and allows using loops, conditionals, classes, and packages to build reusable, testable infrastructure components.
Instructions
- Install the CLI with a package manager:
brew install pulumi/tap/pulumi(macOS/Linux),choco install pulumiorwinget install --exact --id Pulumi.Pulumi(Windows). Or download a release tarball fromgithub.com/pulumi/pulumi/releasesand check it against thepulumi-<version>-checksums.txtfile in the same release (sha256sum -c) before extracting. Current release: 3.272 (October 2026). - Pick a backend:
pulumi loginuses Pulumi Cloud (CI setsPULUMI_ACCESS_TOKEN);pulumi login file://~/.pulumi-statekeeps state in a local directory;pulumi login s3://my-team-pulumi-stateuses a bucket. Local and bucket backends encrypt secrets with a passphrase: setPULUMI_CONFIG_PASSPHRASE(orPULUMI_CONFIG_PASSPHRASE_FILE) in non-interactive runs. - Scaffold:
pulumi new aws-typescript(alsoaws-python,aws-go,azure-typescript,gcp-python,kubernetes-typescript,typescript...). Thenpulumi installto fetch dependencies and plugins if the template did not already, andpulumi stack init dev. - Preview, deploy, inspect:
pulumi preview --diff,pulumi up(add--yesonly in CI),pulumi stack output,pulumi destroy.pulumi refreshsyncs state with the real cloud;pulumi importadopts existing resources;pulumi up --target <urn>limits an update. - Resources and outputs: declare resources with
new aws.s3.Bucket("assets", {...}). A property of another resource is anOutput<T>, not a plain value: transform it with.apply()or thepulumi.interpolatetagged template. Passing an output as another resource's input creates the dependency automatically. A secret stays secret throughapply. - Config and secrets:
pulumi config set aws:region eu-west-1,pulumi config set --secret dbPassword ..., read withconfig.requireSecret("dbPassword"). Secrets are stored encrypted inPulumi.<stack>.yaml;pulumi stack output --show-secretsreveals them. Prefer Pulumi ESC environments (pulumi env) or OIDC for cloud credentials rather than long-lived keys. - Stacks: one stack per environment (
dev,staging,prod) with per-stack config. Share values withnew pulumi.StackReference("my-org/network/prod")and.getOutput("vpcId"). - Component resources: extend
pulumi.ComponentResource, callsuper("org:module:Type", name, {}, opts), create children with{ parent: this }, and finish withthis.registerOutputs({...}). - Policy (CrossGuard): write a policy pack with
@pulumi/policy(or the Python package) and run it aspulumi preview --policy-pack ./policyorpulumi up --policy-pack ./policy. - Unit tests:
pulumi.runtime.setMocks({ newResource, call }, project, stack, dryRun)before importing the code under test, then assert on resource outputs with Vitest, Jest or pytest. No cloud calls are made.
Examples
Example 1: Stack with secret config and a reusable component
User request: "Start a Pulumi TypeScript project for the billing service with a dev stack and a secret DB password"
mkdir billing-infra && cd billing-infra
pulumi new aws-typescript --name billing-infra --stack dev --yes # also creates the dev stack and installs @pulumi/aws
pulumi config set --secret dbPassword "correct-horse-battery-staple"
pulumi up --yes
pulumi stack output
// site.ts
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
export class StaticSite extends pulumi.ComponentResource {
public readonly bucketName: pulumi.Output<string>;
constructor(name: string, opts?: pulumi.ComponentResourceOptions) {
super("billing:web:StaticSite", name, {}, opts);
const bucket = new aws.s3.Bucket(`${name}-assets`, {}, { parent: this });
this.bucketName = bucket.bucket;
this.registerOutputs({ bucketName: this.bucketName });
}
}
// index.ts (replaces the generated one)
import * as pulumi from "@pulumi/pulumi";
import { StaticSite } from "./site";
const config = new pulumi.Config();
const dbPassword = config.requireSecret("dbPassword");
const site = new StaticSite("portal");
export const bucketName = site.bucketName;
export const passwordLength = dbPassword.apply((p) => p.length); // output stays a secret
Result: pulumi preview lists the stack, the component and its child bucket as creates; after pulumi up the outputs show bucketName and passwordLength [secret]. (The component and secret-config flow were run against a local backend with the random provider; the AWS bucket needs real credentials.)
Example 2: Share a network stack and enforce policy
User request: "The api stack needs the VPC from the network stack, and CI must block public buckets"
import * as pulumi from "@pulumi/pulumi";
import * as aws from "@pulumi/aws";
const network = new pulumi.StackReference("acme-platform/network/prod");
const vpcId = network.getOutput("vpcId");
const sg = new aws.ec2.SecurityGroup("api-sg", { vpcId, description: "api tier" });
pulumi preview --diff --policy-pack ../policies/s3-private
Result: the preview fails with the policy violation message before anything is deployed.
Example 3: Unit-test a component without a cloud
import * as pulumi from "@pulumi/pulumi";
pulumi.runtime.setMocks(
{
newResource: (args) => ({ id: `${args.name}_id`, state: { ...args.inputs, bucket: args.name } }), // provider-computed outputs are absent from inputs
call: (args) => args.inputs,
},
"billing-infra", "dev", false,
);
describe("StaticSite", () => {
it("exposes a bucket name", async () => {
const { StaticSite } = await import("./site"); // import AFTER setMocks
const site = new StaticSite("portal");
const name = await new Promise<string>((res) => site.bucketName.apply(res));
expect(name).toContain("portal");
});
});
Guidelines
- Treat
Output<T>as a promise-like value: never use it in string templates orifdirectly; useapply,interpolateorpulumi.all([...]). - Never hardcode credentials; use
config set --secret, ESC or OIDC. Do not commit passphrases. Back up the passphrase or key: losing it makes encrypted config unrecoverable. - Read the preview before every
pulumi up; look forreplaceanddeleteon stateful resources (databases, buckets). Protect them with{ protect: true }orretainOnDelete. - Do not rename a resource in code without an
aliasesentry, or Pulumi deletes and recreates it. - Name resources so they stay unique across stacks; let Pulumi auto-name physical resources (it appends a random suffix) unless a fixed name is required.
- Commit
Pulumi.yamlandPulumi.<stack>.yaml; never commitnode_modulesor local state directories that contain secrets. - Export outputs that other stacks or apps consume (URLs, ARNs, IDs), not everything.
- Use
pulumi destroyandpulumi stack rmonly on stacks you mean to remove;stack rmon a stack with resources needs--forceand orphans them.