Skip to content
tezvyn:

Pulumi: Infrastructure as Code with Real Programming Languages

Source: pulumi.comHardHow cards are made

Pulumi: Infrastructure as Code with Real Programming Languages

Pulumi is Infrastructure as Code using real languages like Python or TypeScript, not a special DSL. This lets you use loops, functions, and classes to define resources. The main footgun is writing overly complex, clever code that becomes unmaintainable.

Why it exists

To provide an alternative to domain-specific languages (DSLs) like Terraform's HCL for Infrastructure as Code. DSLs can be limiting for expressing complex logic, reusing code, or writing tests. Pulumi was created to bring standard software engineering practices and languages to the world of infrastructure management.

The mental model

Think of Pulumi as writing a program that, when executed, declares a desired state of cloud infrastructure. Instead of just a static blueprint, you write a script in a language you already know. This script uses familiar constructs like functions, loops, and classes to define resources. The Pulumi engine then reconciles the output of your program with the actual state in the cloud.

How it works

You write a program in a supported language like TypeScript, Python, Go, or C#. This program uses Pulumi SDKs to declare cloud resources (e.g., an S3 bucket, a Kubernetes deployment). When you run pulumi up, the engine executes your code, computes the desired resource graph, compares it to the current state stored in a backend, and generates a plan to create, update, or delete cloud resources to match your code's declarations.

When to use it

Use Pulumi when your team is more comfortable with a general-purpose programming language than a DSL. It excels at creating dynamic infrastructure (e.g., based on an API call), building reusable components with clear interfaces (like a class for your company's standard web service), and enabling robust unit and integration testing of your infrastructure code using standard frameworks.

When not to use it

Avoid Pulumi if your team prefers a purely declarative, simpler syntax. The power of a full language can be a liability, leading to overly complex or "magical" infrastructure code that is hard for new team members to understand or for on-call engineers to debug during an incident. A simple, static declaration is often safer.

One canonical example

A common use case is defining a variable number of similar resources. Instead of copying and pasting configuration blocks, you can use a simple for loop in Python or TypeScript to create N subnets in a VPC or to provision a set of IAM roles based on a list of team names read from a configuration file.

Interview question

Which statement best describes a core advantage of Pulumi's approach to Infrastructure as Code compared to DSL-based tools?

  • a.It completely eliminates the need for a separate state file or backend.
  • b.It provides a simpler, more declarative syntax for defining all cloud resources.
  • c.It guarantees that infrastructure deployments are always immutable.
  • d.It enables the use of general-purpose programming constructs like loops and classes for resource definition.Correct
Why?

The card highlights that Pulumi uses real programming languages, allowing for complex logic, code reuse, and constructs like loops and classes, which DSLs often limit. Option B is incorrect because while Pulumi aims for clarity, using full programming languages can lead to more complex code than a purely declarative DSL, as noted in the 'When Not To Use It' section.

Just read this? Test yourself on what you have been reading.

Read the original → pulumi.com

You just looked this up. Could you explain it out loud?

That is the part interviews actually test. Tezvyn takes questions like this one and gives you what the interviewer is really checking, the answer that lands, and the mistake that ends the conversation, in the four minutes before your next meeting.

The iPhone app is on the way

We are building it. Until it lands, nothing here is held back from you: every interview card, your saved cards, streaks and the job board all work in Safari, plus hundreds of free practice quizzes of thirty questions each. Sign in and it all carries over to the app the day it arrives.

Want it as an icon? Tap Share at the bottom of Safari, then Add to Home Screen. It opens full screen and the cards you have read stay available offline.

Get it on Google PlayiPhone app coming soon

We are hiring for this. Open roles that interview on iac — each one lists the topics its interview covers.

See open roles