Pulumi Explained: Infrastructure as Code in TypeScript, Python and Go
How Pulumi works: real programming languages for infrastructure, stacks and state, previews and updates, comparing Pulumi with Terraform, and testing.
Published December 4, 2026
Pulumi takes a different approach to infrastructure as code: instead of a configuration language like HCL, you write infrastructure in general-purpose languages such as TypeScript, Python, Go, C# or Java. You get loops, functions, classes, package managers, IDE autocompletion and unit testing frameworks you already know, while Pulumi still computes a declarative plan of resources.
The concept
A Pulumi program declares resources by creating objects (new aws.s3.Bucket(...)). When you run pulumi preview or pulumi up, the engine runs your program, builds a graph of desired resources, compares it with the stack's state, and shows and applies the differences, much like Terraform's plan and apply. Resource outputs are asynchronous values that Pulumi resolves as resources are created.
Each deployment target is a stack (dev, staging, prod) with its own configuration and state, stored in Pulumi Cloud or a self-managed backend such as S3. Secrets in configuration are encrypted. Pulumi can use Terraform providers through bridges, so provider coverage is broad.
How Pulumi works
Pulumi vs Terraform
| Terraform / OpenTofu | Pulumi | |
|---|---|---|
| Language | HCL | TypeScript, Python, Go, C#, Java, YAML |
| Abstractions | Modules | Functions, classes, component resources, packages |
| Testing | terraform test, external tools | Unit tests with language test frameworks |
| State | Backends, HCP Terraform | Pulumi Cloud or self-managed backends |
| Ecosystem / hiring | Very large, HCL widely known | Growing; leverages existing language skills |
Workflow
- pulumi new aws-typescript
- Write resources in index.ts
- pulumi config set (per stack, secrets encrypted)
- pulumi preview → review diff
- pulumi up → apply
Practical examples
A bucket and a CDN in TypeScript
Outputs flow between resources.
import * as aws from "@pulumi/aws"
const site = new aws.s3.BucketV2("site")
const cdn = new aws.cloudfront.Distribution("cdn", {
enabled: true,
origins: [{ originId: "s3", domainName: site.bucketRegionalDomainName }],
defaultCacheBehavior: {
targetOriginId: "s3", viewerProtocolPolicy: "redirect-to-https",
allowedMethods: ["GET", "HEAD"], cachedMethods: ["GET", "HEAD"],
forwardedValues: { queryString: false, cookies: { forward: "none" } },
},
restrictions: { geoRestriction: { restrictionType: "none" } },
viewerCertificate: { cloudfrontDefaultCertificate: true },
})
export const url = cdn.domainNameLoops are just loops
Create one bucket per environment.
for (const env of ["dev", "staging", "prod"]) {
new aws.s3.BucketV2(`logs-${env}`, { tags: { env } })
}Stack configuration and secrets
Per-stack values; secrets encrypted in config.
pulumi stack select prod
pulumi config set aws:region ap-south-1
pulumi config set --secret dbPassword 'S3cure!'
pulumi upCommon mistakes
- Using imperative side effects (API calls) inside programs instead of resources.
- Over-engineering abstractions so infrastructure becomes hard to read.
- Treating outputs as plain values (they are asynchronous Output types).
- Mixing stacks or state backends inconsistently across teams.
Key takeaways
- Pulumi uses real languages to declare infrastructure.
- Preview/update computes and applies a diff like Terraform.
- Stacks separate environments with encrypted config.
- Great for teams that want language features and unit tests.
FAQ
Is Pulumi free?
The CLI and SDKs are open source; Pulumi Cloud has free and paid tiers, and you can self-manage state.
Can I convert Terraform to Pulumi?
Pulumi offers conversion tooling for HCL, and it can consume Terraform providers.
Which language should I pick?
The one your team already knows best, usually TypeScript or Python.