Azure-Pulumi Service Broker
AI Disclaimer
As it’s meant for learning, this project does not contain any AI generated code1 nor was the architecture ideated using AI. The documentation and write-up, however, are written with the assistance of an LLM. My decision to not use AI to assist with programming my pet projects doesn’t reflect an anti-ai sentiment for use during company work.
1Except for the unwrapOneof function here . I couldn’t figure out how to properly cast the isTemplates_Template oneOf interface in my generated protobuf code to my custom interface for Template without having to manually write cases for each possible template that implemented isTemplates_Template.
Overview
The Azure-Pulumi service broker is an gRPC API that allows users to provision templated infrastructure to Azure through Pulumi. In practice, it solves the problem of needing to supply repeatable infrastructure through user requests. The current implementation is a proof of concept with a lot of room for improvement if you were to actually deploy it to a production environment - I speak about this in more detail in What I Would Change.
You can find the code to it here: https://github.com/htemuri/azure-pulumi-service-broker 
Demo using example/client/main.go
Background
I decided to build this project after watching a video by Vasilios Syrakis  where he describes a service that he developed for Atlassian. His project was an internal tool for developers to get envoy proxies for their applications and it followed the Open Service Broker API specification . This reminded me of an idea I had working at the CDC where we had to provision Azure infrastructure on demand for CDC projects. The thought was to write a service broker, similar to Vasilios’, for CDC users to “order” infrastructure self-service instead of them having to create tickets leading to meetings with my team.
Our existing solution was a bunch of terraform modules for different Azure resource types, and for each type and environment combination, we would instantiate the modules for each project. For example, for dev storage accounts, our main.tf could look like this:
# terraform_resources/dev/storage_account/main.tf
locals {
source = "../../../../terraform_modules/storage_account"
env = "dev"
}
module "project-a" {
source = local.source
environment = local.environment
project_name = "a"
...
}
module "project-b" {
source = local.source
environment = local.environment
project_name = "b"
...
}
...
module "project-c" {
source = local.source
environment = local.environment
project_name = "c"
...
}These files would be updated manually until we created a powershell script that would append text to the main.tf files on a CICD pipeline trigger. While this was a great improvement to the original process, with a growing number of resource types supported, changes to resource property conventions, and an increasing influx of requests - maintaining that script became very difficult.
The problem of provisioning infrastructure for projects from a catalogue that follows our internal conventions is deterministic one and can be solved with an API. The Azure-Pulumi Service Broker provides that API and improves reliability by adding protobufs and a strict type system.
What the Project Does
At its core, a client sends a CreateProject gRPC request describing a project: a name, an environment (dev/tst/stg/prd), and a list of templates it wants provisioned. I created some sample templates to show what they might look like:
- Base: Subscription, Vnet/Subnets
- Security: Key Vault (with Private Endpoints)
- Storage: Storage Account (with Private Endpoints)
The broker API doesn’t provision anything itself. It publishes the request to NATS JetStream and immediately hands back a deploymentId. A separate pulumi-worker process picks the job up off the queue, runs the corresponding Pulumi programs against Azure through the Automation API, and writes the result back to a NATS key-value store - success or failure, along with whatever resource outputs came out of the deployment (resource IDs, connection strings, etc). The client polls GetProjectStatus with the deploymentId until it gets back a terminal status.
I designed it this way because provisioning can take minutes, and I didn’t want to hold a gRPC connection open (or time one out) for the whole deployment. Splitting submission from execution also keeps the broker API itself cheap and stateless - the workers are the only piece that actually needs to scale with deployment load.
Technical Implementation
The whole API surface is defined in protobuf (proto/), which gives strict typing across the wire - request/response shapes per template, enums for environment/region/status, and a oneof for the template variants. Everything gets compiled to Go with protoc. Each template includes a property dependsOn which is a list of other templates that a given template depends on (like the name suggests). The broker pulumi worker topologically sorts the templates requested and installs them in order of dependency.
The full flow looks like this:
broker-apireceives aCreateProjectRequest, marshals it to protobuf bytes, and publishes it to aProjectJobQueueJetStream stream under a subject likecreate.<deploymentId>.pulumi-workerruns a durable JetStream consumer against that stream, unmarshals the request, and dispatches each requested template to its corresponding Pulumi program via the Automation API.- The result gets marshaled into a
GetProjectStatusResponseand written into a NATS KV bucket keyed bydeploymentId. GetProjectStatusjust reads that key back out.
Using protobuf for both the gRPC contract and the queue payload meant I didn’t need a second serialization format for internal messaging - the same generated types flow all the way from client, to broker, to worker, and back to client again.
Why am I using Pulumi?
I wanted to write the actual infrastructure logic in a real programming language instead of HCL. Templates need to share a common DefaultParams block, branch on environment, and loop over things like subnets or private endpoint sub-resources - all of which is straightforward in Go and clunkier in Terraform’s expression language.
More specifically, I’m using Pulumi’s Automation API, which lets you drive Pulumi programmatically from inside a Go service rather than shelling out to the Pulumi CLI. That’s really what makes the whole “broker calls Pulumi as a library” model possible - the worker isn’t wrapping a CLI subprocess, it’s importing Pulumi and running stacks directly against my Go template functions.
Things I Learned / Hardships
This was my first time using NATS, protobuf, gRPC, and Pulumi together, so most of the learning curve on this project was just getting comfortable with the stack itself.
NATS turned out to be a lot more versatile than I expected going in. I’d only ever thought of it as a pub/sub system, but JetStream gives you durable streams, consumers, and a key-value store on top of the same server - which is why I ended up using it for both the job queue and the deployment status store instead of reaching for something like Redis or a database alongside it.
Protobuf, on the other hand, felt a lot heavier than I expected. It’s great for getting strict types across the wire, but the generated code is bloated, and things that feel like they should be simple - like casting a generated oneof interface to my own custom interface - end up requiring workarounds like the unwrapOneof function in pkg/templates/template.go.
Pulumi’s Azure Native provider was a highlight - it’s generated directly from Azure’s ARM REST API spec, so it stays a lot closer to what Azure actually exposes than hand-maintained providers tend to. Where I ran into limits was the Automation API itself: it’s fine for running local Pulumi programs like mine, but it’s currently lacking when it comes to deploying from remote sources - like a GitHub repo or actual Pulumi Templates - which is why this project ended up with templates hardcoded into the worker instead of pulled in dynamically.
What I Would Change
This is a proof of concept, and there’s a handful of things I’d want to fix before trusting it in production:
- No rollback path: if a deployment partially fails, there’s currently no automated way to tear back down what did succeed.
- No export/sync story: deployed infrastructure only exists as Pulumi state; there’s no way to export it to a repo-trackable format (Terraform HCL, Pulumi stack files, ARM/JSON) for review or drift detection.
- No NATS auth or TLS: right now anything that can reach the NATS server can publish jobs or read the deployments KV store.
- Templates are Go code, not real Pulumi Templates: I originally wanted actual Pulumi Templates , but the Automation API doesn’t support that yet (tracked upstream ), so templates are hardcoded in
pkg/templatesinstead of pluggable or remote. - No telemetry: there’s no visibility into deployment duration, failure rates, or queue depth beyond reading logs.