Terraform vs Pulumi: What to Use in 2022?

Traditionally, provisioning an infrastructure meant a team of field engineers, system admins, storage admins, backup admins, and an application team would all provision and maintain an on-premises data center. Although this system works, it has a few flaws—slow deployment, high cost of setup and maintenance, limited automation, human error, inconsistency, and the underutilization of resources during off-peak periods.

Romaric Philogène

Romaric Philogène

December 8, 2021 · 6 min read
Terraform vs Pulumi: What to Use in 2022? - Qovery
Written byRomaric Philogène

Romaric Philogène

CEO and co-founder of Qovery. Romaric has 10+ years of experience in R&D. From the Ad-Tech to the financial industry, he has deep expertise in highly-reliable and performant systems.

See all articles
TerraformBusiness

Instead, big tech companies have begun to develop fully managed cloud-based infrastructures, making it possible to fully provision an organization's infrastructure with just a few clicks. While this has immensely relieved the pressures of an on-premises system, this solution still lacks a much-needed consistency that helps eliminate human error and enhance speed. Attempts to solve this problem have led to today's approach of using infrastructure as code (IaC).

Infrastructure as code is a contemporary design that helps to provision, customize, and manage an organization's data center in the cloud, rather than in on-premises data centers. With high-level and simple human-readable code, you can easily create an EC2 instance in AWS.

Although there are several IaC solutions in the market, this article will focus on comparing just two of them:

  • Terraform, a popular older tool with vast platform support and documentation
  • Pulumi, a newer, fast-growing, and developer-friendly tool

A High-level Comparison of Terraform and Pulumi

Terraform and Pulumi are two great solutions that aim to solve similar problems using different approaches. Whether a developer would choose to use one over the other largely depends on the organization and the developer's background.

Those with an admin background tend to lean toward Terraform, and those with a development background typically prefer to write in the same language and go with Pulumi. Terraform is a wise choice for organizations and developers who have the time and resources to invest in learning a Domain Specific Language (DSL). Those who prefer provisioning infrastructure in a more familiar language stack tend to choose Pulumi.

Terraform is the current industry leader in IaC. It's mature and stable, and although you must learn a DSL—namely, HashiCorp Configuration Language (HCL)—Terraform boasts a robust and established community. If you need to learn HCL, the community has enough information to support you and make the learning curve easier to navigate.

Pulumi's strength is that, as a developer, you don't need to learn a new programming language to use it. You can implement all your imperative approaches to writing code in your legacy language. Pulumi provides functionality for approaches like classes, control flow, test scripts, and blocks of code, putting you in control. Write code in your favorite language and still achieve everything you could have done using Terraform.

AWS S3 Bucket Setup with Terraform vs Pulumi
AWS S3 Bucket Setup with Terraform vs Pulumi

The previous image compares a simple code snippet for creating an AWS S3 bucket instance using Terraform and Pulumi. On the left side, the file name has the .tf extension, for Terraform. As you learned earlier, to provision and manage your infrastructure, you need to learn HashiCorp's Configuration Language (HCL). Although the HCL being declarative is simple to set up, it has a steep learning curve.

The code on the right is a Pulumi code written in Python. You can see that the extension is .py. With Pulumi, there's no need to learn a new programming language. Pulumi's support for some major languages like Python, JavaScript, TypeScript, Go, and C# means you can start provisioning your infrastructure right away.

Let's dive into Terraform and Pulumi a little deeper, and understand the circumstances where they each shine.

Terraform

Terraform is a modern open-source IaC tool used for provisioning and maintaining cloud infrastructures. Its DSL, HCL, is a declarative language, which essentially means that you can tell Terraform what to do and it will execute it. This type of language avoids the creation of blocks of code, control flow, and classes. Because of this simplicity, it's easy to start and create your first infrastructure.

Terraform supports all the major cloud infrastructure in the market, providing detailed and easy-to-use documentation for each provider. It's compatible with almost all operating systems (Windows, Linux, and macOS), and its robust documentation captures fine detail as to how to configure resources from all providers. While Pulumi also boasts good documentation, Terraform's is superior.

Terraform has been around since 2014, gaining stability and growing consistently ever since. Like Pulumi, Terraform supports provisioning in all major cloud platforms. However, as noted previously, Terraform's major drawback is that you have to learn HCL.

Pulumi

Like Terraform, Pulumi is an open-source, modern IaC tool used to configure, deploy, and maintain resources on cloud infrastructures. It also supports all major cloud providers, but unlike Terraform, Pulumi allows you to write your infrastructure in native programming languages.

To illustrate how simple it is to provision a resource in Pulumi, consider the following code snippet from a Python file.

From __main__.py:

import pulumi
from pulumi_aws import s3

# Create an AWS resource (S3 Bucket)
bucket = s3.Bucket('my-bucket')

# Export the name of the bucket
pulumi.export('bucket_name', bucket.id)

Let's break down the various components of that code:

  • The first line imports Pulumi.
  • The second line imports S3 from Pulumi's AWS provider called pulumi_aws.
  • The third line is to instantiate the S3 bucket and save it in a variable named bucket.
  • The last line of code exports the bucket.

To put it simply, you can use Pulumi just like every other Python package—you can build your blocks of code, write control flow, create classes, and do everything you do with a general-purpose language, because it's imperative. It was built with the interest of developers at heart, which is a huge reason it's growing so rapidly.

Both Pulumi and Terraform have their ways of managing state. While Pulumi leverages any general-purpose language and Pulumi service, the Terraform engine handles its own state management.

Comparing these two solutions, Pulumi comes out ahead. While both tools are effective in providing developers with a consistent way of provisioning IaC, developers are typically more attracted to a tool that allows them to write code in a language they already know and use. Pulumi has also upped its game by providing a way to help developers convert their HCL code into Pulumi through tf2pulumi.

As ambitious as Pulumi is, however, Terraform isn't exactly sleeping. HashiCorp has introduced Terraform CDK, their Cloud Development Kit that allows developers to use familiar programming languages to define cloud infrastructure provision.

Conclusion

In this article, you learned about infrastructure as code and the relevance of Pulumi and Terraform as two of the most popular tools in the industry. While both solutions accomplish similar goals, they use different approaches that appeal to developers for a variety of reasons.

While Terraform is a longstanding tool with excellent platform support and a deep well of documentation, Pulumi shines in its inclusive nature with support for a vast array of programming languages.

The continuous iteration of existing systems and technologies has led to tremendous advancement in how we provision infrastructure. For instance, Pulumi came into the market to disrupt and improve the services that Terraform has provided for years. To a great extent, they have succeeded.

In the same way, Qovery has come to build the future of the cloud. Built for developers, DevOps teams, project managers, and CTOs, it provides a robust platform to deploy your applications easy to deploy in the cloud.

Whatever your IaC tool of choice may be, Qovery can reliably simplify your application deployments.

Deliver Self-Service Infrastructure, Faster!

Qovery turns your existing IaC infrastructure and Kubernetes manifests into repeatable blueprints for complete environments.

Try it out now!
Deliver Self-Service Infrastructure, Faster!