Pulumi as Infrastructure as Code software

Dimas Adinugroho
Oct 8, 2018 · 4 min read


This is the blog posts in which we try to outline our experience regarding the engineering at HARA. HARA is a blockchain-based data exchange for the food sector and provides farmers and all agriculture player access to reliable data and transactions. If you want to know HARA in depth, please check our medium page.

Today, many company used terraform as a tools for configure their favorite cloud infrastructure. This will makes their configuration more accurate and well documented, we know this as Infrastructure-as-Code (IAC). No exception at HARA, we used terraform to build our cloud infrastructure because they provides many benefits. We also use serverless framework to deploy application on serverless architecture. Everything is great, but today we are not going to talk about this two or other tools. There is another way to build infrastructure as well as serverless on cloud that is Pulumi and we decide to explore this tool as alternative. You might as well try pulumi (By the time writer write this, pulumi version is 0.14.1)

Getting started on Pulumi

Their websites is a good starting place, install pulumi on your computer and sign up in their websites to access our console . Because pulumi is also supported immutable infrstructure like terraform, when you create resources, all of the activity and states of your infrastructure will be recorded in their websites. Its different from terraform when you can store “resources states” in many way (you need to specify the backends on terraform).

Create token first and enter your access token when you are prompted or just save your token with name PULUMI_ACCESS_TOKEN as environment variables and you will be set.

Image for post
Image for post
New Access Token

There are several providers that supported on pulumi (GCP, Azure, AWS and Kubernetes). Pulumi create several packages to support each provider, that is:

  • @pulumi: used for accessing the core programming model around resources, configuration, etc.

When you want to compare terraform and pulumi, Terraform is more like Infrastructure as Declarative Statement. As for Pulumi, there are four programming languages that has been supported, that is: Python, Go, Typescript or Javascript. For nodejs SDK in pulumi itself, is written using TypeScript.

An example that i provide will be using AWS as cloud provider. I will create simple program to create IAM user resources using Javascript. I will use code that already been in terraform (check here) and transform into Pulumi.

To start, type: pulumi new aws-javascript in empty folder and pulumi will initialize and create a new project. Fill the project name, project description and stack name. New files will be created (.js and .yaml files) and node_modules depedencies will be installed in that folder.

First, we need to import @pulumi and @pulumi-aws. We can create IAM user by using aws.iam.User class. To provides additional access key or login profile, we use aws.iam.AccessKey and aws.iam.UserLoginProfile class.

In Pulumi, it requires to specify the unique nameas first argument passed to the resource constructor, this is how they recognize if the resource already exist or not. To create dependencies between resources, just references the output properties of resource (the output of createUser used as argument on createAccessKey). You could add another function like add user to the group membership or attach policy the the user. After we create the functionUser.js, now we define the main function.

To preview the changes in our stack before applying, type pulumi preview. In terraform it is same as terraform plancommand. We can see that our stack already have 2 resources before and will create 1 resource that is UserLoginProfile.

Image for post
Image for post
Pulumi preview

After finishing the preview, we can type pulumi updateto apply or update the stacks. In terraform it is same as terraform apply command. This command will adjust the existing resouces and creates new resources based on previous stacks. You can see the history of you stacks in pulumi console.

Image for post
Image for post
Pulumi Update

When you want to see the output in the latest stack, just type pulumi stack output. We can add more users by updating list or delete user by simply comment the function. With this, we can control IAM users easier and readable. You can also use loop function to iterate through user list, its your choice.

Many people needs more feature on terraform (rather than just a “declarative” programming) even though maybe you can hack-your-way into it. Also, as someone like me who more familiar with programming languages like Javascript, pulumi is great choice to provide resources or write applications in our cloud infrastructure. Just give it a try.

HARA Engineering

HARA is a decentralized, secure and transparent platform…

Medium is an open platform where 170 million readers come to find insightful and dynamic thinking. Here, expert and undiscovered voices alike dive into the heart of any topic and bring new ideas to the surface. Learn more

Follow the writers, publications, and topics that matter to you, and you’ll see them on your homepage and in your inbox. Explore

If you have a story to tell, knowledge to share, or a perspective to offer — welcome home. It’s easy and free to post your thinking on any topic. Write on Medium

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store