Infrastructure as Real Code
Terraform popularized infrastructure as code with HCL, a domain-specific language. Pulumi takes a different approach: use real programming languages you already know - TypeScript, Python, Go, C#, Java.
This is not just syntax preference. Real languages bring real capabilities: loops, conditionals, functions, classes, type checking, testing frameworks, IDE support, and package ecosystems.
The Programming Model
Pulumi programs declare desired state. Resources are objects. Dependencies are inferred automatically from how you pass outputs to inputs.
When you run pulumi up, Pulumi compares desired state to actual state and computes the minimal set of changes. Same model as Terraform, different interface.
The key insight: infrastructure code is still code. It should be readable, testable, and maintainable. Real languages make this natural.
TypeScript Advantages
TypeScript is particularly powerful for infrastructure:
Type safety: Catch configuration errors at compile time. Misspelled property names, wrong types, missing required fields - all caught before deployment.
IDE support: Autocomplete shows available resources and properties. Jump to definition. Refactoring tools work.
Familiar ecosystem: npm packages, testing frameworks, linting, formatting - use the same tools as your application code.
Component Resources
Pulumi's killer feature is component resources - reusable abstractions that encapsulate complexity.
Build a WebApplication component that creates an S3 bucket, CloudFront distribution, Route53 records, and SSL certificate. Consumers create a WebApplication with a few parameters, without understanding the underlying resources.
This enables platform teams to encode best practices into components that application teams consume. Guardrails built in, complexity hidden.
Testing Infrastructure
With real code comes real testing:
Unit tests: Mock the Pulumi engine and verify resource configurations. Does the bucket have versioning enabled? Are tags applied correctly?
Property tests: Verify invariants across all resources. All S3 buckets must have encryption. All security groups must not allow 0.0.0.0/0.
Integration tests: Deploy to a test environment, run assertions, tear down. Verify the infrastructure actually works.
State Management
Pulumi tracks state to know what exists and what changed. State backends:
Pulumi Cloud: Managed state, collaboration features, policy enforcement. Easiest option.
Self-managed: S3, Azure Blob, GCS. You manage the backend, Pulumi manages the state format.
State contains sensitive data. Encrypt it. Control access to it.
Stacks: Environments Done Right
Stacks represent different instances of the same infrastructure: dev, staging, production. Same code, different configuration.
Use stack configuration for environment-specific values: instance sizes, replica counts, domain names. The code stays identical across environments.
Best Practices
Recommended Reading
💬Discussion
No comments yet
Be the first to share your thoughts!
