IaC
Pulumi
Infrastructure as Real Software using TypeScript, Python, or Go.
Pulumi
Pulumi allows you to define infrastructure using general-purpose programming languages (TypeScript, Python, Go, C#).
Why use code?
- Loops & Logic: Use real
forloops,ifstatements, and string manipulation rather than complex interpolation syntax. - Abstractions: Create classes and functions to abstract complex infra patterns into reusable libraries (e.g., an npm package for your company's standard microservice).
- Testing: You can write Unit Tests for your infrastructure using standard test runners (Jest, Pytest).
Pulumi vs. Terraform
| Feature | Terraform | Pulumi |
|---|---|---|
| Language | HCL (DSL) | TS, Python, Go, C# |
| State | .tfstate (S3/Local) | Pulumi Service (SaaS) or S3/GCS |
| Learning Curve | Low (Easy to read) | High (Need to know coding) |
| Secrets | Plaintext in state (usually) | Encrypted by default |
The Programming Model
Pulumi builds a dependency graph of resources. It executes your code to generate this graph, then compares it to the current cloud state.
import * as aws from "@pulumi/aws";
// Create an S3 bucket
const bucket = new aws.s3.Bucket("my-bucket", {
acl: "private",
tags: {
Environment: "Dev",
},
});
// Export the name of the bucket
export const bucketName = bucket.id;When to use Pulumi?
- Complex Logic: If your infrastructure requires complex conditional logic or API calls to external systems during build time.
- Developer-Centric: If your team is composed mostly of application developers who already know TypeScript/Python.
- Multi-Cloud: Like Terraform, Pulumi works across AWS, Azure, GCP, and Kubernetes simultaneously.