Pulumi Vs Terraform: The future of cloud engineering?
Traditionally, infrastructure setup was a manual and a very lengthy process. Now, Infrastructure as Code (IaC) tools have transformed this process by paving a way towards a more efficient means of setting up infrastructure. Most IaC tools automate infrastructure configuration and management through the use of scripts or configuration files. Numerous solutions have been developed to implement Infrastructure as Code, each with their own strengths and weaknesses. Two IaC tools often used are Terraform from HashiCorp and Pulumi from a venture-backed start up. Now I will try to explain the functionality and then discuss their use cases like in which situations which one is preferable.
What is Terraform and its features?
Terraform is one of the popular infrastructure as code tool that has become standard within DevOps. Terraform is an open source IaC tool used for developing, changing and versioning infrastructure quickly and efficiently. It can handle lower-level elements, such as storage and networking devices, as well as higher-level components, including DNS entries. Terraform is ideal for building and managing infrastructures for various reasons as discussed below:
- Terraform is open source and has a large supporting community. Thus, we have seen that Terraform quickly evolves with continual improvements.
- Terraform is platform agnostic. Terraform can provide infrastructure across any cloud service provider like AWS, Azure, Google Cloud, etc.
- Terraform is also a declarative tool, Terraform being a declarative tool means that a developer can simply describe a desired end-state infrastructure for running an application, and the plan to reach that end-state is created and carried out automatically.
- Terraform provisions an immutable infrastructure. Provisioning an immutable infrastructure further leads to other key benefits such as preventing configuration drift. Configuration drift is typically being caused by IaC tools that create a mutable infrastructure which allows for the infrastructure to accommodate for changes.
What is Pulumi and its features?
Pulumi is a modern Infrastructure As Code innovative platform that bridges the gap between developers and cloud providers. It takes advantage of existing programming languages like Node JS (TypeScript), Python, .NET(C#), or Go to interact with your Infrastructure through its SDKs downloaded onto devices locally as well as accessed over internet connections. It can deploy, manage, and update cloud infrastructure, containers, databases, and hosted services. Pulumi can provision both lower-end components such as storage and networking, and higher-level elements. Some features of pulumi are discussed below:
- Open-source: Pulumi is a language-neutral infrastructure automation platform that doesn’t require you to learn any new programming languages. It works with all the most popular cloud platforms like AWS, GCP, and Microsoft Azure.
- Multi-language support: Instead of writing your infrastructure configuration in a programming language, use IaC platforms like Pulumi. This way, you can stay away from domain-specific languages.
- Feature-rich CLI: Through the Pulumi CLI, deploying cloud infrastructure is a simple process. You can use it on Linux or Windows to deploy server less applications with just one command.
- Dry-run support: Pulumi supports the dry run feature through the pulumi preview command. This command shows a preview of the scheduled updates to a stack so that developers can verify that no unintended changes are deployed.
The Benefits of Moving from Terraform to Pulumi?
- Language options: Terraform uses a domain-specific-language called HashiCorp Configuration Language (HCL), the problem with this is that it enforces a strict schema and also supports a variety of cloud providers. It poorly implements basic control flow like
switchstatements. However Pulumi supports many languages like Node.js, Python, .NET Core, Go So writing your infrastructure as code in a familiar, widely used language is better than using HCL, as you can directly jump in to it.
- Dynamic Resource Creation at Runtime: If you are using external configuration database, then with Terraform you have to write a python file to read your external datasource. The problem with this is when you want to create an unknown number of resources. So you have to define the node count per environment( development and production ) in a configuration database. So this is pretty much hectic as it requires the count at runtime. As a solution, you could write a python script that runs cli commands to create the node pools but still you cannot track the current state and also you wont be able to cater error handling as well. On the other hand, Pulumi does not have this limitation.
pulumi previewshows you what your configuration database defines. Resource state is tracked, errors are handled, and the code is readable.
- Ease of deployment: By default, if you want to deploy components to the cloud infrastructure with Terraform, you need to use a SaaS platform. To deploy components from a local drive using Terraform, you need to add specific variables to the Terraform cloud ecosystem. However, with Pulumi, you can deploy resources from a local drive seamlessly.
- GitOps Support: As most of you are unaware about the GitOps, so lets try to first explain it in simple terms, it is basically a deployment methodology centralized around a Git repository, where any new code merged to a Git repo triggers a deployment to various environments and clusters in real-time. The Pulumi Operator allows us to leverage the power of Pulumi at the application team level for GitOps. This means we can have a strictly typed exchange of “knowns” between our platform and our application that happens at execution time. However there is no such support for GitOps by terraform.
In my humble opinion Pulumi is better than Terraform. Hands down. It has all the features of Terraform, but written with the simplicity and power of a fully featured programming language.
As Pulumi offers more flexibility and more focus on functions, while Terraform has better documentation and solid community support. I would rather suggest that if you don’t know either Terraform or Pulumi, I would suggest you use Pulumi even if you don’t know any programming language. It’s in my opinion the right way to do infrastructure as code. Furthermore, it is better to learn a programming language that could be useful somewhere else than HCL which you will only use in HashiCorp products. In the end, you should choose the solution you feel is more appropriate to you and your project, and that you think will be easier for you to learn and use in the long term. If it’s Terraform then go with it! If it’s Pulumi, welcome to modern Infrastructure as Code!