Pulumi and Typescript

Pulumi and Typescript.

Introduction

I have mainly used Terraform when implementing cloud infrastructures as code (IaC). I have really liked Terraform - the hcl configuration language is powerful and nice to work with IntelliJ, which provides a plugin with great developer experience (syntax highlighting, autocompletion, etc.)

A couple of years ago, I worked on a project (you can read more about the project in My First Project at Metosin!) in which the devops team decided to use Pulumi with Python - we created various cloud resources in AWS (e.g., EKS). Before starting to use Pulumi, we created a short POC implemented both using Terraform and Pulumi; you can read more about that comparison in my previous blog post, Terraform vs. Pulumi Experiences. Regarding that short comparison, both tools seemed to be a good choice - we chose Pulumi and decided to use Python with Pulumi.

Later on, when implementing EKS using Pulumi/Python, we had quite a few oddities and challenges. My impression at that time was that Pulumi was not as mature as Terraform, and if I could make the choice, I would continue using Terraform in my cloud projects. Also, choosing Python as the implementation language was a poor choice - it turned out that most of the examples used Typescript - we should have chosen Typescript as the implementation language.

New Impressions

A couple of years passed. I started a new project two weeks ago. The customer uses Pulumi with Typescript in the Google Cloud Platform, GCP. I have spent a couple of weeks familiarizing myself with the cloud infrastructure code and started implementing new features. I write some short first impressions using Pulumi with Typescript in this recent blog post.

Pulumi

I believe Pulumi has developed to be more mature now than a couple of years ago when I first started using it. A couple of years ago, I remember that it was a bit of a struggle to get the Pulumi code right so that we could create the EKS in one pulumi up run. Our new customer also uses Kubernetes, but in the GCP side the Google Kubernetes Engine, GKE. This time there was absolutely no hassle: GKE with node pool, cluster, and some other resources were up and running in some 12 minutes after the pulumi up command. Well, I must also say, that the Kubernetes infrastructure seems to be a lot simpler in GCP than in AWS.

There are two kinds of source files you need with Pulumi. First, you need a stack configuration for a new environment; you add this to Pulumi.ENV.yaml file (ENV can be e.g., prod, perf dev…). In the stack configuration, you can add various stack-specific parameterizations. But the really nice thing with Pulumi is that you can use a real programming language when implementing your cloud resources (compared to hcl, which you must use with Terraform).

Typescript

Our customer uses Typescript. You can use various other programming languages as well: Javascript, Python, Go, C#, Java, etc. I think Typescript is a excellent choice with Pulumi, since the startup is fast (I’m not sure if using Java Pulumi starts a new JVM process every time or keeps the JVM running in the background), and you get type support (which you don’t get with Javascript). VSCode is a natural choice with Typescript - I haven’t tried other editors, but with VSCode using Pulumi with Typescript, you get excellent developer experience - syntax highlighting, autocompletion, etc. I have used Typescript previously only a couple of months some years ago, so the Typescript / Javascript syntax took a couple of days to get used to, but you don’t have to be a Typescript guru with Pulumi - most of the code is pretty simple and straightforward, and basically, you can learn the language on the fly when implementing your infrastructure as code.

An example of the Typescript type safety in Pulumi IaC:

interface Budget {
  threshold_percent: pulumi.Input<number>;
  ...
}
const budgetParams = config.requireObject<Budget>("budget");

And don’t forget: Since you are using a real programming language, you can use all language ecosystem in your infrastructure code. E.g., when using Typescript, you can use any Javascript/Typescript library you feel makes you more productive with your Pulumi code.

Conclusions

My new first impressions of Pulumi are better than those two years ago. I think the Pulumi team has done excellent work:

  • The tool is excellent.
  • There is a vibrant community using Pulumi.
  • The Pulumi documentation is just great.

I’m really looking forward to deep diving using Pulumi with Typescript - who knows, maybe Pulumi will replace Terraform as my IaC tool of choice in my future cloud projects.

The writer is working at Metosin using Clojure in cloud projects. If you are interested to start a cloud or Clojure project in Finland or you are interested getting cloud or Clojure training in Finland you can contact me by sending an email to my Metosin email address or contact me via LinkedIn.

Kari Marttila

Kari Marttila’s Home Page in LinkedIn: https://www.linkedin.com/in/karimarttila/