Pulumi: not our beloved Terraform, but in a good way

I’ve been using terraform since at least 0.11. I’ve been using it forever and I really enjoy the idea and implementation for the most part. But in a deluge of small projects where I’m no longer using terraform for large-scale infrastructure, I’ve been looking for something a bit quicker to get started with. After falling in love with pyinfra for my homelab, I wanted something similar for the cloudflare/VPS bits of my infrastructure.

Terraform is fantastic for large-scale infrastructure. It’s main drawback is that HCL and the tooling aren’t quite there yet if you’re trying to move quickly. Getting completions and hints when you’re just trying to get your site working is a bit of a pain. Enter Pulumi.

Pulumi has 5-6 different language SDKs, and I’ve been using the typescript one. Let’s just jump into a quick example of how I set up the Cloudflare pages domains for this site:

let blogDomains = ["alexw.codes", "alexh.codes"];
const accountId = ...;
const domains = blogDomains.map(d => pcf.getZone({name: d, accountId}));

const project = ...;
const pagesRecords = domains.map(async z => {
	const awaited = await z;
	const projectArgs = {
		accountId,
		projectName: project.id,
		domain: `blog.${awaited.name}`,
	};
	return new pcf.PagesDomain(awaited.name, projectArgs)
});
const domainRecords = domains.map(async z => {
	const awaited = await z;
	return new pcf.Record(awaited.name, {
		name: "blog." + awaited.name,
		type: "CNAME",
		content: project.subdomain,
		proxied: true,
		zoneId: awaited.zoneId,
	})
})

It’s almost a little too easy to buy a domain and get it set up with cloudflare now. But this is nothing that terraform won’t do. The real tangible benefits come from not having to deal with the initial terraform setup, the wonky plugins, and trying to get things working dynamically. I like xs.map(x => new pcf.Y(x)) a lot more than equivalent mess of fors, interpolations, and plugins in terraform for my small projects.

A Caveat

No really, I love terraform. I think I would still heavily consider it if I were working on a larger project. Being a lot more strictly declarative can cut down on team rogues writing a bunch of wonky code.