Comparing three popular Infrastructure as Code (IaC) tools: Terraform, Crossplane, and Pulumi.

Matías Salinas
4 min readMar 12, 2023

--

Infrastructure as Code (IaC) is a method of managing and provisioning infrastructure through code. By using IaC tools, developers can automate the creation, modification, and deletion of cloud resources such as virtual machines, networks, and storage. We’ll compare three popular IaC tools: Terraform, Crossplane, and Pulumi.

Terraform

Terraform is an open-source IaC tool created by HashiCorp. It has been around since 2014 and is one of the most widely used IaC tools. Terraform supports multiple cloud providers and can manage a wide range of resources, including virtual machines, databases, and load balancers.

Advantages:

  • Supports a wide range of cloud providers
  • Has a large and active community with many plugins and modules available
  • Uses a declarative language to define infrastructure
  • Supports state management for tracking changes to infrastructure

Disadvantages:

  • Steep learning curve for beginners
  • Can be verbose and difficult to read and maintain for larger infrastructure
  • No native support for multi-cloud deployments

Example Code:

Here’s an example Terraform code that creates a virtual machine in Microsoft Azure:

provider "azurerm" {
subscription_id = "YOUR_SUBSCRIPTION_ID"
client_id = "YOUR_CLIENT_ID"
client_secret = "YOUR_CLIENT_SECRET"
tenant_id = "YOUR_TENANT_ID"
}

resource "azurerm_resource_group" "example" {
name = "example-resources"
location = "West US"
}

resource "azurerm_virtual_network" "example" {
name = "example-vnet"
address_space = ["10.0.0.0/16"]
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
}

resource "azurerm_subnet" "example" {
name = "example-subnet"
address_prefix = "10.0.1.0/24"
resource_group_name = azurerm_resource_group.example.name
virtual_network_name = azurerm_virtual_network.example.name
}

resource "azurerm_network_interface" "example" {
name = "example-nic"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name

ip_configuration {
name = "example-config"
subnet_id = azurerm_subnet.example.id
private_ip_address_allocation = "Dynamic"
}
}

resource "azurerm_windows_virtual_machine" "example" {
name = "example-vm"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
network_interface_ids = [azurerm_network_interface.example.id]
size = "Standard_DS1_v2"

storage_image_reference {
publisher = "MicrosoftWindowsServer"
offer = "WindowsServer"
sku = "2016-Datacenter"
version = "latest"
}

storage_os_disk {
name = "example-os-disk"
caching = "ReadWrite"
create_option = "FromImage"
managed_disk_type = "Standard_LRS"
}

os_profile {
computer_name = "example-vm"
admin_username = "adminuser"
admin_password = "Password1234!"
}

os_profile_windows_config {
enable_automatic_upgrades = true
provision_vm_agent = true
}
}

Crossplane

Crossplane is an open-source IaC tool created by Upbound. It aims to provide a unified way to manage infrastructure across multiple cloud providers and on-premises environments. Crossplane uses a Kubernetes-like API to define infrastructure, which allows for a familiar experience for those already using Kubernetes.

Advantages:

  • Supports a wide range of cloud providers and on-premises environments
  • Uses a familiar Kubernetes-like API to define infrastructure
  • Enables infrastructure-as-code with the use of GitOps principles

Disadvantages:

  • Requires knowledge of Kubernetes and its ecosystem
  • Can be complex for beginners
  • Limited community support and plugins compared to Terraform

Example Code:

Here’s an example Crossplane code that creates an Amazon S3 bucket:

apiVersion: storage.crossplane.io/v1alpha1
kind: Bucket
metadata:
name: my-s3-bucket
spec:
forProvider:
name: my-s3-bucket
acl: private

Pulumi

Pulumi is a newer IaC tool that allows developers to use familiar programming languages like Python, TypeScript, and Go to define infrastructure. Pulumi supports multiple cloud and his providers including AWS, Azure, GCP, and Kubernetes.

Advantages:

  • Allows developers to use familiar programming languages to define infrastructure
  • Supports multiple cloud providers and Kubernetes
  • Provides infrastructure-as-code with real programming languages
  • Enables easy integration with existing software development workflows

Disadvantages:

  • Can be complex for beginners
  • Limited community support and plugins compared to Terraform
  • Some features may be still in beta or experimental

Example Code:

Here’s an example Pulumi code that creates an AWS S3 bucket:

import pulumi
import pulumi_aws as aws

bucket = aws.s3.Bucket("my-s3-bucket",
acl="private",
tags={
"Environment": "dev",
})

pulumi.export("bucket_name", bucket.id)

Conclusion:

Terraform, Crossplane, and Pulumi are all powerful IaC tools that provide different approaches to infrastructure automation. Terraform uses a declarative language to define infrastructure, while Crossplane uses a Kubernetes-like API, and Pulumi allows developers to use real programming languages to define infrastructure.

Choosing the right IaC tool depends on your team’s needs, skills, and infrastructure requirements. Terraform is a mature and widely adopted tool with a large community and many plugins. Crossplane provides a Kubernetes-native way to manage infrastructure and enables infrastructure-as-code with GitOps principles. Pulumi offers a familiar programming language experience for infrastructure definition and integrates easily with existing software development workflows.

Overall, all three tools offer powerful and flexible ways to manage infrastructure, and the choice ultimately depends on your specific use case and preferences.

--

--

Matías Salinas
Matías Salinas

Responses (1)