Infrastructure-as-Code with Pulumi

Using a public cloud like Microsoft Azure or Amazon AWS? Chances are you’ve been using templates like ARM or CloudFormation.

Hashicorp has done a terrific job making Terraform with the ability to template any API, and deploy and manage stacks in Azure, AWS and many, many more.

I’ve been following Pulumi for a while, and their approach is a bit different than the previous stated tools.

Pulumi states their product as follows:

Modern Infrastructure as Code.

Declare cloud infrastructure using real languages. Enable developers and operators to work better together.

With ‘real’ languages they mean programming languages. At this moment JavaScript, TypeScript, Python, Go, or any .NET language, including C#, F#, and VB are supported. I did some testing with C#, and although it is in preview, it works great:

Pulumi_0_Languages

Installing Pulumi

The install is pretty simple. This page will get you up and running in no time. I personally used Chocolatey but you can download the tool for Windows, MacOS and Linux if you want.

Getting Started with Azure

The getting started guides work great. The only thing you need (in my example for Azure) is an account. The page https://www.pulumi.com/docs/get-started/azure/ show you a step-by-step guide.

Deploying resources

I’ve picked a simple setup, having one resource group in Azure, with one Storage Account. To deploy the stack to Azure, a simple ‘pulumi up’ command fires up Pulumi. Just like Terraform, you can see what will happen if you deploy this command. In this case you see that a Stack in Pulumi is created, and a resourceGroup and storage account will be setup in Azure:

Pulumi_1_deployfirsttime

After choosing ‘yes’, you will see Pulumi actually deploying your stack. In the picture below the account has been created, and we see the output plus duration (don’t worry, the storage account has been deleted so the key not valid anymore):

Pulumi_2_deploymentcreated

Updating resources

The next step shows what happens if we update something in the stack. In this case, we have updated that the storage account only allows HTTPS traffic. The pulumi up command shows us the expected changes, and shows us it will update the storage account:

Pulumi_3_incrementalupdate

After choosing yes, the update will start, and it will display the next image. As you can see, 1 resource was updated, and 2 were unchanged:

Pulumi_4_incrementcompleted

Destroying resources

To destroy your resources, pulumi destroy will tear down everything, up until the stack in Pulumi itself:

Pulumi_5_destroy

Wait, Pulumi Stack?

Pulumi defines stacks of your deploys. To quote them on this:

Every Pulumi program is deployed to a stack. A stack is an isolated, independently configurable instance of a Pulumi program. Stacks are commonly used to denote different phases of development (such as development, staging and production) or feature branches (such as feature-x-dev, jane-feature-x-dev).

So, you can look at these like your set of resources. You can group them under Projects so it can be easier to manage. The webinterface of Pulumi is clean, and you can inspect all of your stacks and settings there:

PulumiStack

Conclusion

This short blog is just to show you that there is more than the standard way of working with the cloud. Obviously you can use various APIs, SDKs or templates, but these sometimes can be a bit overwhelming for developers. Pulumi lets you choose your language, and makes sure your developers do not need to learn another language and still use the modern infrastructure-as-code techniques!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s