Pulumi with Terraform – the easy way
Christian Lechner
Posted on August 30, 2024
Introduction
Some time ago I did some experimentation with bridging the Terraform Provider for SAP BTP to get a Pulumi provider. While this was not an easy task it was doable, and I could get things up and running.
I learned that some improvements have been made for this exercise at the Kubernetes Community Days Munich 2024, but did not yet follow up on them. And that was good. Why? Because hot of the press a blog post landed in the Pulumi blogs that sounded too. Good to believe: Introducing: Support For Using Any Terraform Provider with Pulumi.
What the blog post basically says is that with one pulumi command you can now create the Pulumi provider by referencing the Terraform provider for the language you want to write your setup with. Can you believe that? Well, I gave a try, and I was stunned. Curious what I saw? Then follow along.
Disclaimer
As I am working for SAP some disclaimer (that you are certainly used to from SAP folks): this blog post should show your options when you would like to use Pulumi for setting up resources on SAP BTP. There is no official support of Pulumi from SAP (at least at the time when writing this blog post).
With this statement let the fun start.
Generating Pulumi from the provider
I had the Pulumi CLI installed and followed a long the blog post. As JavaScript and TypeScript are languages that are heavily used in the SAP ecosystem, I decided to go for Typescript for my Pulumi setup.
After doing the authentication dance with pulumi login
I created a new TypeScipt project via:
pulumi new typescript
After the scaffolding complete, the next step was the magic one: create a local Pulumi provider from the Terraform provider
pulumi package add terraform-provider SAP/btp
After that there it was ... the SDK based on the Terraform provider:
The generation just took a few seconds and looking into the code, it looked decent.
What to do next? The output of the command also gives you advice on that namely executing
npm add btp@file:sdks/btp
In addition, the output states to add the import
of the SDK to the index.ts
. Very convenient experience lowering the entry barrier a lot. Been there done that.
But now the moment of truth has come. Let us give it a try and deploy some resources to SAP BTP.
Giving it a try
First, we need to put some code into the index.ts
so that Pulumi knows what to do. I did a simple setup with a directory and a subaccount underneath:
import * as btp from "btp";
const directory = new btp.Directory("my-dir-from-pulumi")
const subacountParameters: btp.SubaccountArgs = {
description: "my subaccount from pulumi",
parentId: directory.id,
region: "us10",
subdomain: "my-subaccount-from-pulumi"
}
const subaccount = new btp.Subaccount("my-ssubaccount-from-pulumi", subacountParameters)
Nothing fancy, but for a first try that should do the trick. I did not want to do a production grade setup, so I added the necessary configuration parameters via CLI:
pulumi config set btp:globalaccount 'MyGlobalAccountSubdomain'
pulumi config set btp:username 'My Email'
pulumi config set btp:password 'MySecretPassword' --secret
Configuration done, so let't give the deploy a try:
pulumi up
The output of the CLI said that it worked:
and so does the result on SAP BTP:
Awesome stuff!
Summary
The new functionality of Pulumi to create a language-specific SDK based on a Terraform provider is nothing less than breath-taking. It is straightforward to get the SDK and make use of it. The generated code (at least for TypeScript where I tested it) looks decent, so easy to generate and to use. Although the feature is brand-new when publishing this blog post, I can definitely recommend to give it a try.
As to be expected for a new feature there are also some known gaps that probably will be closed over time like generating the documentation. This clearness on what's possible and what is not (yet) is highly appreciated.
I also want to say that the experience with the Pulumi CLI is great. It has very good hints and makes your start especially for Pulumi newbie like me a smooth experience.
With that happy Terrafo .... ahh Pulumiing!
Posted on August 30, 2024
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.