
Infrastructure
Pulumi vs Terraform: The Language Is No Longer the Choice
Pulumi vs Terraform: Pulumi now runs .tf files and Terraform providers, so choose on engine, licence, secrets in state and what it costs to leave.
Most comparisons still open with a table: Pulumi has loops, types and unit tests; Terraform has HCL, a plan, and a larger community. That table was a fair summary in 2022. It is a poor one now, because both sides spent the intervening years absorbing each other's arguments.
This article puts the language question in its place, then spends most of its length on the things that decide whether a platform team can still own its toolchain in ten years: the engine's licence, the shape of secrets in state, the backend you run, and the exit.
The axis everyone compares has mostly collapsed
Pulumi's language docs list "TypeScript, JavaScript, Python, Go, .NET, Java, YAML, and HCL." Pulumi HCL is a language plugin that lets you author Pulumi programs in Terraform's HCL syntax while using Pulumi's state management, secrets handling and deployment engine. In Pulumi's words, it "runs the same .tf files you would write for Terraform or OpenTofu": a project is a Pulumi.yaml with runtime: hcl plus one or more .tf files, and it needs Pulumi CLI 3.256.0 or later.
name: simple-hcl
runtime: hcl
description: A simple Pulumi HCL project
Treat "the same .tf files" as Pulumi's claim about a young plugin, not proven parity. The same page documents the edges: backend, provider_meta, required_version and experiments in the terraform block are accepted but ignored with a warning, because Pulumi manages state itself; a cloud block is an error; Terraform state files are not read or written; and provisioner connection blocks support SSH only.
Providers converged earlier. The Pulumi Terraform Bridge "adapts any Terraform Provider built using the Terraform Plugin SDK for use with Pulumi," and Pulumi publishes a terraform-provider package to "use any Terraform provider with Pulumi." For providers built on that SDK, the resource code underneath both tools is largely shared, though schema mapping and defaults can differ.
The middle path closed too. HashiCorp's CDK for Terraform — general-purpose code on the Terraform engine — was announced to "sunset and be archived on December 10, 2025," with HashiCorp saying it "did not find product-market fit at scale"; the repository has since been archived read-only. General-purpose code on a maintained Terraform engine is gone; HCL now runs on three engines.
So the decision moves to four axes: the engine and its governance, the secrets model in state, the backend and its failure modes, and the cost of leaving. Language still matters to the people writing the code. It just no longer forces the rest.
Where real code helps and where it lets infrastructure sprawl
for_each, count, dynamic blocks, locals and modules cover most of what platform teams loop over. The real constraint is temporal. Terraform's docs state that all values for_each iterates over "must be known before Terraform performs any remote resource operations," and the count value carries the same rule. You cannot fan out over an attribute the cloud only returns after apply; you split the configuration, or run twice.
A general-purpose language moves the modelling into the type system and the standard library. Here is a Pulumi Python program that declares environments as a typed dataclass, loops over them, and reads a secret from stack config:
"""One artifact bucket per environment, plus one secret parameter."""
from dataclasses import dataclass
import pulumi
import pulumi_aws as aws
@dataclass(frozen=True)
class Env:
owner: str
retention_days: int
ENVS: dict[str, Env] = {
"dev": Env(owner="platform", retention_days=7),
"prod": Env(owner="platform", retention_days=365),
}
config = pulumi.Config()
db_password = config.require_secret("dbPassword") # encrypted in state
buckets: dict[str, aws.s3.Bucket] = {}
for name, env in ENVS.items():
buckets[name] = aws.s3.Bucket(
f"artifacts-{name}",
tags={
"env": name,
"owner": env.owner,
"retention-days": str(env.retention_days),
},
)
aws.ssm.Parameter(
"db-password",
type="SecureString",
value=db_password,
)
pulumi.export("buckets", {name: b.bucket for name, b in buckets.items()})
Nothing here is impossible in HCL — a map(object({...})) variable and for_each express the same shape. What code adds is a compiler or type checker, an IDE that knows the resource schema, shared libraries published through the language's own package manager, and the ability to compute things HCL's function set does not offer.
A Pulumi program can call HTTP APIs, read files, branch on the clock, or import a library with side effects. HCL's limits are partly a review contract. If you choose code, write the contract down: no network I/O outside providers, no non-deterministic inputs, components with typed arguments, and previews in every pull request.
Testing: mocks on both sides now
Unit tests used to be Pulumi's cleanest argument. Pulumi's unit-testing guide explains that mocks "stand in for the Pulumi CLI, answering your program from inside the same process," and that you use whichever test framework you prefer. The test below runs the program above under pytest with no cloud credentials, using the mock API the guide documents for Python:
"""Unit test: every bucket carries an env tag. Runs with pytest, no cloud calls."""
import runpy
import unittest
import pulumi
class Mocks(pulumi.runtime.Mocks):
def new_resource(self, args: pulumi.runtime.MockResourceArgs):
return [args.name + "_id", args.inputs]
def call(self, args: pulumi.runtime.MockCallArgs):
return {}
class TestBuckets(unittest.IsolatedAsyncioTestCase):
def setUp(self):
pulumi.runtime.set_mocks(Mocks(), preview=False)
pulumi.runtime.set_all_config({"project:dbPassword": "test-only"})
self.program = runpy.run_path("__main__.py")
@pulumi.runtime.test
def test_buckets_are_tagged_with_env(self):
def check(args):
name, tags = args
self.assertEqual(tags.get("env"), name)
bucket = self.program["buckets"]["prod"]
return pulumi.Output.all("prod", bucket.tags).apply(check)
Two details from the guide bite in practice. Explicit output properties returned from new_resource must use camelCase whatever the language. And mock-based unit testing "needs a general-purpose language runtime" — YAML and HCL programs are pointed at integration testing instead. A team that adopts Pulumi HCL to keep its .tf files gives up Pulumi's mocks in the same move.
Terraform closed most of the gap from its side. terraform test runs .tftest.hcl files, and test mocking — mock_provider blocks and resource overrides — is available in Terraform v1.7.0 and later. The assertions are HCL, but testing module logic without touching a cloud exists on both sides. Testing is now a question of which language your team already tests well in, not which tool can test at all.
State and secrets: three different models
This is where the three tools differ most, and where marketing language ("encrypted state") hides the most.
Terraform: keep secrets out, encrypt at the backend
Terraform's sensitive-data guide is blunt: developing locally, "Terraform stores your state in a plaintext file, which includes any secret values you defined in your configuration." It recommends remote state so it can be encrypted at rest — by the backend, not by Terraform. Marking a value sensitive redacts it from output; it is still in state.
The newer answer is to keep secrets out entirely. Ephemeral values need Terraform 1.10 or later, and Terraform does not store ephemeral resources in state or plan files. Write-only arguments need 1.11 or later and are never written to state — so Terraform "has no way of knowing if a write-only argument value has changed," so a rotation has to be signalled some other way.
OpenTofu: encrypt state and plan files with your key
OpenTofu added optional end-to-end state encryption in v1.7.0. Per the encryption docs, it encrypts state and plan files at rest, both locally and in a backend. Documented key providers are PBKDF2, AWS KMS, GCP KMS, Azure Vault, OpenBao, OVHcloud KMS (external) and External. The configuration lives in the terraform block:
variable "state_passphrase" {
type = string
sensitive = true # at least 16 characters
}
terraform {
encryption {
key_provider "pbkdf2" "main" {
passphrase = var.state_passphrase
}
method "aes_gcm" "main" {
keys = key_provider.pbkdf2.main
}
state {
method = method.aes_gcm.main
enforced = true
}
plan {
method = method.aes_gcm.main
enforced = true
}
}
}
Read the caveats on the same page. Encrypted state is unrecoverable without the key. Encryption does not protect against data loss or against a replay with an older state file, and "OpenTofu does not and cannot protect the sensitive values in the state file from the person running the tofu command." Existing plaintext state needs a migration step with an unencrypted fallback method. If the key lives in OpenBao, the secret store becomes a hard dependency of every plan.
Pulumi: encrypt the values you mark
Pulumi encrypts at a finer grain. Per its secrets docs, values marked secret "never appear as plain text in your state file"; by default the CLI uses "a per-stack encryption key managed by Pulumi Cloud, and a per-value nonce." On a DIY backend you supply keys — a stack passphrase, or a KMS such as awskms, azurekeyvault, gcpkms or hashivault chosen with --secrets-provider.
Only marked values are encrypted. Every other input and output is plaintext, and a resource's physical ID "is always stored in plain text in the state file and cannot be encrypted." random.RandomString exposes its result as its id, so the generated string lands in state unencrypted even if result is marked secret; use RandomPassword. Write-only fields go the other way from Terraform: per Pulumi's write-only docs, the initial value is written to state inputs as an encrypted secret.
Who holds the state: Pulumi Cloud, a DIY backend, or your bucket
Pulumi's state and backends page is candid about the default: "the hosted Pulumi Cloud," with self-managed storage trading control for "having to handle security, state management, auditing, and other concerns." DIY backends cover AWS S3, Azure Blob Storage, Google Cloud Storage, an S3-compatible server such as MinIO or Ceph, a PostgreSQL database, or the local filesystem — pulumi login s3://… or pulumi login postgres://….
Locking: Pulumi's DIY backend guide says "a basic file-based locking system is enabled by default for all DIY backends," with per-stack lock files under the backend's .pulumi/locks/ prefix while an operation runs. Terraform's S3 backend is the opposite default: use_lockfile "defaults to false" — locking is opt-in — and DynamoDB-based locking is deprecated but still works until it is removed; the two can be configured simultaneously to support migration. OpenTofu's S3 backend differs: use_lockfile enables native S3 locking and is opt-in, and DynamoDB locking remains supported — "the OpenTofu team has no plans to deprecate either option." An S3 backend is unlocked only when it sets neither.
Recovery from partial failure: here Pulumi's own docs draw the line against DIY. Pulumi Cloud "records every checkpoint through a transactional API," which lets it recover from failures such as network interruptions mid-update. DIY backends keep checkpoint history in .pulumi/history/, but "because they are fundamentally limited by the non-transactional protocols of blob storage, they cannot transparently recover from certain kinds of partial failures." An interrupted pulumi up becomes your incident. pulumi refresh adopts provider drift for resources already in state; it does not replace Pulumi Cloud's recovery. That limit is worded for blob storage; the docs also list PostgreSQL as a DIY backend.
For Terraform and OpenTofu, the bucket is the backend, and the state layout is yours to design — the subject of Terragrunt vs Terraform and of the provider-native comparison in Terraform vs CloudFormation.
Automation API versus wrapping a CLI
Pulumi's Automation API encapsulates pulumi up, pulumi preview, pulumi destroy, pulumi stack init and the rest "as a strongly typed SDK." That lets a platform team embed infrastructure operations in a service — a self-service portal that creates a stack per tenant, or a test harness that stands an environment up and tears it down — with typed results instead of parsed text.
Read the page closely, though. It opens by describing a way to run Pulumi programs "without the Pulumi CLI," then notes that Automation API "drives the Pulumi CLI under the hood, so the CLI must be available to your program at runtime." Your service image carries the CLI and its version, exactly as a Terraform wrapper carries terraform or tofu.
The Terraform and OpenTofu equivalent is wrapping the CLI yourself: -json output, machine-readable plans, and an orchestrator such as Terragrunt or a CI system. It is less ergonomic and more portable — the wrapper is yours, and the binary underneath is swappable between two forks. Automation API is the better developer experience; it also deepens the dependency on one engine.
Licence and governance: who can change the terms
- Pulumi. The CLI and engine are Apache-2.0. The project is single-vendor; Pulumi Cloud is a separate commercial service and the default backend.
- Terraform. Licensed MPL 2.0 through v1.5.7; from v1.6.0 it is under the Business Source License, whose v1.6.0 grant excludes offering it to third parties "on a hosted or embedded basis which is competitive with HashiCorp's products," with each version converting to MPL 2.0 four years after publication; the current grant on
mainis worded differently. IBM completed its acquisition of HashiCorp on 27 February 2025, and the licence text onmainnow names IBM as licensor. - OpenTofu. MPL 2.0, and accepted into the CNCF at Sandbox level on 23 April 2025.
As of 29 November 2026 the current stable releases are Pulumi v3.278.0, Terraform v1.17.2 and OpenTofu v1.13.10. Using Terraform internally is not what the BUSL grant targets; a platform company that embeds an IaC engine in something it sells to customers needs a lawyer's reading of the current text. Apache-2.0 and MPL-2.0 both permit forking, but only OpenTofu sits under a foundation; with Pulumi, the licence protects the code and a single company sets the roadmap. The full fork mechanics are in OpenTofu Migration: The Registry Is the Hard Part.
Exit ramps in both directions
Pulumi documents a migration from Terraform. pulumi convert --from terraform --language python translates HCL; modules become Pulumi components, and unsupported features become TODOs while the command still succeeds. Pulumi estimates the converter "should be able to convert 90-95% of the code without any TODOs" for most projects — a vendor's expectation, not an independent measurement. pulumi import --from terraform reads a Terraform or OpenTofu state file and imports the managed resources from every module in it, marked protected. The converter source names each imported resource by its own name, with no module path, so resources sharing a name and type across two modules collide and the import stops with an "ambiguous URN" error. A clean import still does not mean program and state share URNs. Pulumi's guide has its Neo agent run pulumi preview "to prove no changes"; for a Pulumi HCL project, pulumi import --from hcl builds the module path into the name.
#!/usr/bin/env bash
set -euo pipefail
# 1. State on a DIY backend you run (or: pulumi login postgres://...).
pulumi login s3://example-pulumi-state
# 2. Translate the HCL in this directory; unsupported features become TODOs.
pulumi convert --from terraform --language python
pulumi install
# 3. A stack whose secrets are encrypted with your KMS key, not a hosted one.
pulumi stack init prod \
--secrets-provider="awskms://1234abcd-12ab-34cd-56ef-1234567890ab?region=eu-central-1"
# 4. Import managed resources from state (they arrive protected).
# Plaintext state, secrets included: the trap deletes the copy on any exit.
# Write the copy to its own file: with the local backend, terraform.tfstate
# IS the live state, and a redirect onto it truncates it before the pull.
trap 'rm -f pulled-state.tfstate' EXIT
terraform state pull > pulled-state.tfstate # or: tofu state pull
pulumi import --from terraform ./pulled-state.tfstate
# 5. Resolve every TODO the converter left before trusting a preview.
grep -rn "TODO" --include="*.py" . || true
# 6. A gate. With modules, expect creates plus protected leftovers:
# convert nests module resources under components; the import put
# them at the root. Never "pulumi up" a plan that creates, replaces
# or deletes, and never clear protect to force it.
pulumi preview
Staying on HCL shortens the path: a Pulumi HCL project keeps the .tf files, and pulumi import --from hcl terraform.tfstate brings the state across; per the converter source, it skips, with a warning, only modules the program does not declare — narrower than the migration guide's root-module-only sentence. Remember the ignored backend block — after the import, the bucket you used to trust is no longer the source of truth.
The reverse is the asymmetry. Pulumi documents no converter from a Pulumi program back to HCL. Leaving means rewriting the program by hand and importing each resource into Terraform or OpenTofu state. Between Terraform and OpenTofu, the shared HCL subset runs on both engines; OpenTofu-only features like encryption do not. The cheapest exit ramp is to keep configuration in HCL with providers both forks can consume — whichever engine executes it.
Deciding it for the team that is on call
- Who reviews changes? If reviewers are platform engineers who read plans, HCL's limits are a feature. If infrastructure is authored by application teams who already test in Python or TypeScript, Pulumi's languages, components and mocks earn their keep.
- Who holds the keys? OpenTofu encrypts state and plan files under your key; Pulumi encrypts marked values under Pulumi Cloud's key unless you pick a passphrase or KMS; Terraform relies on the backend and on keeping secrets out of state.
- Where does state live, and who recovers it? Pulumi Cloud buys transactional checkpoints. A DIY Pulumi backend or a Terraform bucket buys control and makes partial-failure recovery your runbook.
- Which licence can your platform tolerate for a decade? Read it against what you plan to build, not what you run today.
The long game is keeping the next move cheap. State outlives the tool that wrote it, as Terraform vs Kubernetes and Terraform vs Ansible both argue from different directions. Choose governance you can live with, keep secrets out of state or encrypted under keys you hold, rehearse the recovery path for whichever backend you run, and know before you start which direction of migration is documented and which is a rewrite.
§FAQ/Common questions
Frequently asked
Can Pulumi run Terraform .tf files?
Yes, via Pulumi HCL, a language plugin that needs Pulumi CLI 3.256.0 or later. A project is a Pulumi.yaml with runtime: hcl plus .tf files, run on Pulumi's engine and state. The backend, provider_meta, required_version and experiments settings in the terraform block are ignored with a warning, a cloud block is an error, and Terraform state is not read; import it with pulumi import --from hcl.
Is Pulumi state encrypted?
Only the values marked secret. Pulumi encrypts those per value, by default with a per-stack key managed by Pulumi Cloud, or with a passphrase or KMS key you supply on a DIY backend. Other inputs and outputs are plaintext, and a resource's physical ID is always plaintext and cannot be encrypted.
Does OpenTofu encrypt state?
Optionally, since v1.7.0. OpenTofu can encrypt state and plan files at rest, locally and in a backend, with key providers including PBKDF2, AWS KMS, GCP KMS, Azure Vault and OpenBao. Encrypted files are unrecoverable without the key, and encryption does not protect values from whoever runs tofu.
Can I self-host Pulumi state?
Yes. DIY backends store state in S3, Azure Blob Storage, Google Cloud Storage, an S3-compatible server, PostgreSQL or the local filesystem, with file-based locking on by default. Pulumi's docs note DIY backends cannot transparently recover from certain partial failures, which Pulumi Cloud's transactional checkpoints handle.
How do I migrate from Terraform to Pulumi?
Run pulumi convert --from terraform --language python (or another language), then pulumi import --from terraform with the state file. Pulumi estimates 90-95% of code converts without TODOs. The state import brings managed resources from every module in the state file, names them without the module path, and marks them protected. Pulumi documents no converter in the reverse direction.
Further reading
- OpenTofu Migration: The Registry Is the Hard Part
- Terragrunt vs Terraform: What Native HCL Covers Without It
- Terraform vs Kubernetes: Provisioning or Reconciling
- Terraform vs CloudFormation: Who Holds the Record
- Terraform vs Ansible: State You Own, State You Converge
- OpenBao vs Vault: Three Gates Before You Move a Secret
Executive Briefing
Thirty minutes to clarify your infrastructure risk
Walk us through your vendor footprint and regulatory constraints. We will tell you honestly where sovereignty creates leverage — and where it does not. No pitch deck. No obligation.