What is Pulumi and How Does It Differ from Terraform?
Learn what Pulumi is, how it uses real programming languages for infrastructure, and how it compares to Terraform — DevOps interview guide.
Expected Interview Answer
Pulumi is an infrastructure-as-code tool that lets you define cloud resources using general-purpose programming languages like TypeScript, Python, Go, or C#, instead of a domain-specific language, while still tracking a declarative desired-state model similar to Terraform.
Under the hood, a Pulumi program executes your chosen language to build a resource graph, and the Pulumi engine then diffs that graph against recorded state (stored in Pulumi Cloud, self-managed, or a supported backend like S3) to compute the same kind of create/update/destroy plan Terraform produces. Because it uses a real language, Pulumi gives you native loops, conditionals, functions, classes, and access to the language’s package ecosystem — for example, calling a shared internal library or writing genuine unit tests for infrastructure logic — capabilities that HCL supports only through more limited constructs like count, for_each, and dynamic blocks. Pulumi also ships a component-resource model, which is conceptually similar to Terraform modules but written as ordinary classes that can encapsulate validation logic and complex control flow. The tradeoff is that a general-purpose language raises the barrier for reviewers unfamiliar with that language, and Pulumi’s provider ecosystem and community module count are smaller than Terraform’s mature registry, though Pulumi does bridge and reuse most Terraform providers under the hood.
- Use familiar general-purpose languages instead of learning a new DSL
- Native loops, conditionals, and testing frameworks for infrastructure logic
- Component resources enable rich, class-based reusable abstractions
- Can bridge and reuse most existing Terraform providers
AI Mentor Explanation
Pulumi is like a coach who plans match strategy using the same general-purpose whiteboard software they already use for every other sport, rather than learning a cricket-only tactics tool from scratch. The coach writes loops and conditional logic in that familiar tool to generate field placements dynamically for any scenario. Terraform, by comparison, hands the coach a purpose-built cricket-tactics language that is powerful but must be learned separately from anything else the coach already knows. Both approaches produce a valid field plan, but Pulumi lets the coach reuse skills and tools they already have.
Step-by-Step Explanation
Step 1
Write infrastructure in a real language
Define resources in TypeScript, Python, Go, or C# using the Pulumi SDK.
Step 2
Pulumi builds a resource graph
Running the program executes your code, which registers resources into an in-memory graph.
Step 3
Diff against recorded state
The Pulumi engine compares the graph to stored state in a backend such as Pulumi Cloud or S3.
Step 4
Preview and update
pulumi preview shows planned changes; pulumi up applies them and updates the stack state.
What Interviewer Expects
- Understanding that Pulumi uses general-purpose languages, not a DSL
- Knowledge that Pulumi still follows a declarative desired-state model under the hood
- Awareness of component resources as the Pulumi analog to Terraform modules
- Ability to discuss tradeoffs: language familiarity/testing vs ecosystem maturity
Common Mistakes
- Assuming Pulumi is purely imperative with no state tracking, unlike Terraform
- Forgetting Pulumi can bridge and reuse many existing Terraform providers
- Ignoring that a general-purpose language raises the review bar for non-developers
- Confusing component resources with plain helper functions that do not register as resources
Best Answer (HR Friendly)
“Pulumi lets us define our infrastructure using a programming language we already know, like Python or TypeScript, instead of learning a brand-new configuration language. It still works declaratively under the hood, tracking a state file and computing diffs just like Terraform, but it gives us real loops, functions, and unit tests for our infrastructure code, which our developers find easier to review and extend.”
Code Example
import * as aws from "@pulumi/aws";
const bucket = new aws.s3.Bucket("dataBucket", {
bucket: "my-app-data-bucket",
tags: { Environment: "production" },
});
export const bucketName = bucket.bucket;
# CLI commands
pulumi preview
pulumi upFollow-up Questions
- How does Pulumi store and lock state compared to Terraform?
- What is a Pulumi component resource and how does it compare to a Terraform module?
- How does Pulumi reuse existing Terraform providers under the hood?
- What are the tradeoffs of using a general-purpose language for infrastructure code?
MCQ Practice
1. How does Pulumi primarily differ from Terraform in configuration authoring?
Pulumi lets engineers define infrastructure in real programming languages while still tracking declarative state, unlike Terraform’s HCL DSL.
2. What is the Pulumi analog to a Terraform module?
Component resources let Pulumi developers group and encapsulate resources similarly to how Terraform modules do, but as ordinary classes.
3. Where can Pulumi commonly source its cloud provider integrations from?
Pulumi often bridges Terraform providers, giving it broad cloud coverage without reimplementing every provider independently.
Flash Cards
What languages does Pulumi support? — TypeScript, Python, Go, C#, and others, instead of a dedicated DSL.
Is Pulumi imperative or declarative? — Code execution is imperative, but the resulting resource graph and state model are declarative.
What is a Pulumi component resource? — A class-based abstraction grouping resources, similar in purpose to a Terraform module.
Where does Pulumi store state? — Pulumi Cloud by default, or a self-managed backend like S3.