DEV Community

Cover image for Pulumi - IaC in your favorite programming language!
TechWorld with Nana
TechWorld with Nana

Posted on

Pulumi - IaC in your favorite programming language!

DevOps tool of the month is a series, where each month I introduce one new useful DevOps tool in 2021 πŸ™ŒπŸΌ

For May I chose: Pulumi πŸŽ‰ - a modern Infrastructure as Code Tool for Developers.

What is Pulumi and how it's different from other IaC tools πŸ’‘

When writing IaC scripts using other tools, you usually have to use a DSL (like HCL in case of Terraform) of that tool or YAML or JSON which is a format that many tools use.

Problem with YAML or JSON:
It's easy to read and easy to define resources you want to create and that is great.

But what if we need to add some logic in there, like

  • conditionals, "create this EC2 instance, if xyz"
  • or use loops, like "I want to create 20 EC2 Instances with the same configuration"
  • or what about re-using logic? Like, "all 20 instances with this shared config, plus some specific configs"

It gets pretty complex in such formats. So all these logical operations, loops, reusing blocks of code is a natural part of any programming language, right?

So writing the same infrastructure as code logic in a programming language would obviously make writing more complex code easier and cleaner. And that's exactly what Pulumi did.

Pulumi allows you to write infrastructure as code in a programming language.

Now which programming language is that? πŸ€” Well, you can actually choose whichever language you want to use Pulumi. You can write it in Node.js, Python, .net etc.

Pulumi - choose favorite language

So instead of having to learn a new syntax or DSL or a new language, you can use the language you are most proficient in and use it for writing infrastructure as code. πŸ‘

Main Benefits of using a Programming Language of your choice 🀩

1) Use the same Programming Tools you know for Infrastructure
If you are coding in Python for example, you probably have the most fitting IDE for it, like PyCharm, you have installed all the plugins for that languages, you have configured linters that tell you immediately if you have an error in the code or warning in your code quality. You know all the main libraries you can use in your code etc.

So you know the whole eco-system of that language. And that means you can use all that same eco-system and your expertise for now writing infrastructure as code. And this can make your work much more efficient.

Use Programming Expertise for Infrastructure

2) Treat Infrastructure as Code as Application Code
Another thing that we see emerging and becoming a standard is treating our infrastructure as code exactly the same way as our application code.

One Pipeline for Everyone

That includes e.g. testing the code. Having unit tests, integration tests etc. So with YAML and JSON format or DSL, like HCL that Terraform uses, it's pretty difficult to write tests for these scripts.

With Pulumi obviously you have the advantage of simply writing tests for you IaC as for your application code, using the same test libraries, same language, same editor etc. πŸ™ŒπŸΌ

How Pulumi works in Practice πŸ‘©πŸ»β€πŸ’»

Check out the video to see how Pulumi works in practice. I will show you how to write a simple Pulumi project to first create an S3 bucket in an AWS account and then a more realistic example of provisioning an EKS cluster:
Pulumi Demo

More awesome tools coming up next on this series, so stay tuned for it! 🎬 😊

Like, share and follow me 😍 for more content:

Top comments (3)

thomasstep profile image
Thomas Step

Have you used the AWS CDK? I would be curious to know if you prefer Pulumi over a tool built by a cloud provider themselves. Of course, that question only really applies if the target cloud is AWS!

schollii profile image

CDK is too things:
1) an SDK (in several programming languages) to generate CloudFormation template files (CFTF);
2) a controller of cloudformation

Pulumi is similar for #1 (just different API), but very different for #2. CF has a purist implementation of state-based infrastructure, ie CF will not let your stack be halfway betwen your original state and your desired state. If this sounds good in theory, it's a pain in practice, I've seen updates via CF fail both the rollout and the rollback! Then what do you do? You're screwed. With terraform, the description of your infrastructure is the state; it will let you get partway there, but always knows where you are on that path.

llbbl profile image
Logan Lindquist

weird name but powerful tool