Infrastructure-as-Code with Pulumi
Tags: azure, azuredevops, cicd
Published: 2019-12-17 06:21:03

---
title: Infrastructure-as-Code with Pulumi
published: true
date: 2019-12-16 14:49:36 UTC
tags: Azure,Azure DevOps,CICD
canonical_url: https://peterrombouts.nl/2019/12/16/infrastructure-as-code-with-pulumi/
---

Using a public cloud like Microsoft Azure or Amazon AWS? Chances are you’ve been using templates like [ARM](https://docs.microsoft.com/en-us/azure/azure-resource-manager/template-tutorial-create-first-template?tabs=azure-powershell) or [CloudFormation](https://aws.amazon.com/cloudformation/).

Hashicorp has done a terrific job making [Terraform](https://www.terraform.io/) with the ability to template **any** API, and deploy and manage stacks in Azure, AWS and many, many more.

I’ve been following [Pulumi](https://www.pulumi.com/)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 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](https://peterrombouts.files.wordpress.com/2019/12/pulumi_0_languages.png?w=840)

## Installing Pulumi

The install is pretty simple. [This page](https://www.pulumi.com/docs/get-started/install/) 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/](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](https://peterrombouts.files.wordpress.com/2019/12/pulumi_1_deployfirsttime.png?w=840)

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](https://peterrombouts.files.wordpress.com/2019/12/pulumi_2_deploymentcreated.png?w=840)

### 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](https://peterrombouts.files.wordpress.com/2019/12/pulumi_3_incrementalupdate.png?w=840)

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](https://peterrombouts.files.wordpress.com/2019/12/pulumi_4_incrementcompleted.png?w=840)

### Destroying resources

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

### ![Pulumi_5_destroy](https://peterrombouts.files.wordpress.com/2019/12/pulumi_5_destroy.png?w=840)

## 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](https://peterrombouts.files.wordpress.com/2019/12/pulumistack.png?w=840)

## 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!