Skip to main content
Terraform vs Pulumi: HCL vs Real Code

Terraform vs Pulumi: HCL vs Real Code

KU
· Founder & Chief Editor
• 8 min read•Updated •22 views

Terraform's declarative HCL and Pulumi's real programming languages solve the same problem in very different ways, and the right pick depends on your team.

Key takeaways

  • Pick Terraform or OpenTofu for most teams: HCL is constrained, readable by non-programmers, and backed by the largest provider registry.
  • Pick Pulumi when your infrastructure is dynamic and your team already writes TypeScript, Python, Go, C# or Java, because you get real loops, abstractions and in-memory unit tests.
  • Both keep state and provision the same clouds.

Choose Terraform (or OpenTofu) if your infrastructure is mostly static and maintained by mixed-skill teams: HCL is constrained, readable, and has the largest provider registry. Choose Pulumi if your team already writes TypeScript, Python, Go, C# or Java and needs real loops, abstractions and unit tests. Both keep state and provision the same clouds.

Verified against

Terraform 1.17.1, OpenTofu 1.13.2, Pulumi CLI 3.273.0, against the HashiCorp Terraform test and S3 backend docs and the Pulumi languages, unit testing and secrets docs. Checked October 2026.

The argument between them is really about one thing: do you want a purpose-built configuration language, or your existing programming language pointed at infrastructure? That choice ripples into how you write loops, how you test, and who on your team can safely make changes.

Terraform / OpenTofuPulumi
LanguageHCL (declarative DSL)TypeScript, Python, Go, .NET, Java, YAML, plus HCL
Loops and logicfor_each, count, ternariesNative language constructs
Unit testingterraform test with command = plan and mock providersJest, pytest, Go tests with mocked resource calls
Default state backendLocal file; S3, GCS, HCP TerraformPulumi Cloud (free for individuals); S3, Azure Blob, GCS
Provider ecosystemLargest registryNative providers plus bridged Terraform providers
Best fitMixed-skill platform teamsSoftware teams with dynamic infrastructure

The philosophical split

Terraform uses HCL, a declarative DSL built only for describing infrastructure. You state the desired end state and the engine figures out the plan. HCL has no classes, no real functions you author, and a deliberately small surface area. That constraint is a feature. A junior engineer can read a .tf file and mostly understand it without knowing a programming language.

Pulumi flips this. You write TypeScript, Python, Go, C# or Java (Pulumi also accepts YAML and, as of 2026, HCL), and the infrastructure is the result of running your program. It reads imperatively but Pulumi still builds a dependency graph and reconciles against state underneath, so the mental model is closer to Terraform than it first appears. The difference is that you now have the entire language available: real functions, packages from npm or PyPI, IDE autocomplete, and type checking.

Loops, conditionals, and abstraction

This is where the contrast gets concrete. Say you want a bucket, or several buckets.

In Terraform with HCL:

HCL
# main.tf
variable "bucket_names" {
  type    = list(string)
  default = ["logs", "artifacts", "backups"]
}

resource "aws_s3_bucket" "this" {
  for_each = toset(var.bucket_names)
  bucket   = "acme-${each.value}-prod"

  tags = {
    Team = "platform"
  }
}

for_each and count cover most iteration needs, and modules give you reuse. But anything conditional gets awkward. You end up with ternaries inside string interpolation and count = var.enabled ? 1 : 0 tricks that read like puzzles once logic gets nested.

The same thing in Pulumi with TypeScript:

TypeScript
// index.ts
import * as aws from "@pulumi/aws";

const names = ["logs", "artifacts", "backups"];

const buckets = names.map((name) =>
  new aws.s3.Bucket(`acme-${name}`, {
    bucket: `acme-${name}-prod`,
    tags: { Team: "platform" },
  })
);

A map is just a map. Need a conditional? Use an if. Need to derive names from an API call at build time? Import a library and call it. This is genuinely more powerful for complex, dynamic infrastructure, and genuinely easier to over-engineer. The freedom that lets you write a clean helper also lets you write a tangle of abstraction that nobody else can follow.

Testing

Testing is Pulumi's strongest structural argument. Because your infrastructure is a normal program, you can write real unit tests with Jest, pytest, or Go's testing package, mock the cloud provider, and assert on resource properties before anything is deployed. You can assert that no security group opens port 22 to the world in a fast in-memory test.

Terraform's testing story has improved a lot: the native terraform test framework can run assertions with command = plan so nothing is created, and it supports mock providers. Tools like Terratest still cover the integration side. The difference is that Terraform tests are written in HCL against a plan, not in your team's everyday test framework. Policy-as-code via Sentinel or OPA covers the guardrail case well. If a strong automated testing culture matters to you, Pulumi fits the habits your developers already have.

State management

Both tools track reality in a state file, and both need that state stored somewhere safe and locked during changes. Terraform points at an S3 backend or at HCP Terraform (formerly Terraform Cloud). If you still lock with DynamoDB, note that the S3 backend docs now mark DynamoDB-based locking as deprecated in favor of use_lockfile = true, which writes a .tflock object next to the state. Since the license change, many teams run OpenTofu, the open-source fork, with the same backends and no vendor tie; our Terraform vs OpenTofu comparison covers that choice.

Pulumi defaults to Pulumi Cloud for state and locking, which is free for individuals, but you can also self-manage state in S3, Azure Blob, or GCS. The operational concerns are identical in both worlds: never edit state by hand, always lock, and back it up.

Provider ecosystem

Terraform's registry is the larger ecosystem by a wide margin, with thousands of providers and a huge library of community modules for nearly anything you can name.

Pulumi bridges most Terraform providers automatically, so coverage is close in practice, but the native, hand-tuned providers and the community module depth are smaller. For mainstream clouds you will not notice a gap. For long-tail integrations, Terraform still has the edge.

Learning curve and team fit

HCL is quick to pick up and hard to misuse. A platform team can hand a .tf file to a data engineer or an SRE and expect a correct change. The ceiling is lower, but so is the floor.

Pulumi rewards teams that already live in a language. A TypeScript shop gets autocomplete, refactoring tools, and shared libraries for free, and the barrier between application code and infrastructure code drops. The risk is that infrastructure inherits your codebase's habits, good and bad, and that a non-programmer on the team is now locked out of the config.

Secrets handling

Both encrypt secrets in state rather than leaving them in plaintext. Terraform marks values sensitive to keep them out of logs and pairs with Vault or cloud secret managers for the actual storage. Pulumi has first-class secret encryption built in: mark a config value as secret and it is encrypted in state and in the config file automatically, using a per-stack key.

How to choose

Pick Terraform or OpenTofu when: your team spans many roles and skill levels, you value a readable and constrained config, you need the widest provider coverage, or you want to avoid depending on a single language ecosystem. It is the safe default for most organizations.

Pick Pulumi when: your infrastructure is genuinely dynamic, you have a strong developer culture that wants real tests and abstractions, your team already writes TypeScript, Python, Go, C# or Java daily, or you are building reusable platform components that benefit from real language features.

Watch out for: choosing Pulumi mainly to avoid learning HCL. The language is the easy part. The hard part is understanding the cloud, and both tools demand that equally.

For the wider field, see our roundup of the best Infrastructure-as-Code tools. If you are already committed to real code, the Pulumi vs AWS CDK comparison is worth a read too.

Questions people ask

Is Pulumi better than Terraform?

Neither is better in general. Pulumi is better for software teams building dynamic infrastructure, because real loops, packages and unit tests in TypeScript, Python, Go, C# or Java pay off there. Terraform is better for mixed teams, because constrained HCL is readable by anyone and the provider registry is the largest. Pick by who will maintain the code, not by feature lists.

Can Pulumi use Terraform providers?

Yes. Many Pulumi providers are bridged from Terraform providers, so coverage of mainstream clouds is close to identical. Pulumi can also consume a Terraform provider that has no published Pulumi package. Long-tail community modules are still deeper in the Terraform registry.

Do I need Pulumi Cloud to use Pulumi?

No. Pulumi Cloud is the default backend and, according to Pulumi's pricing page, free for individuals, but you can store state yourself in S3, Azure Blob Storage, Google Cloud Storage or the local filesystem with pulumi login. Self-managing state means you own backups, locking and secrets-provider configuration, the same chores a Terraform S3 backend gives you.

The call we'd make

For most teams, most of the time, we would start with Terraform or OpenTofu. The constraints of HCL are a form of protection, the ecosystem is unmatched, and the readability keeps infrastructure open to your whole team rather than just the programmers. It is the choice you rarely regret.

We reach for Pulumi when the infrastructure itself is complex enough that real loops, conditionals, and unit tests pay for themselves, and when the team is clearly a software team first. In that setting Pulumi is the better tool. Don't treat this as a religious war. Match the tool to your team, not to the internet's opinion.

Sources

Explore topics:TerraformDevOps
React
Share this post
Cite this article
Plain text

Kiril Urbonas (2026). Terraform vs Pulumi: HCL vs Real Code. DevOpsNess. Updated 2026-10-31. https://www.devopsness.com/blog/terraform-vs-pulumi

Markdown

[Terraform vs Pulumi: HCL vs Real Code](https://www.devopsness.com/blog/terraform-vs-pulumi) (Kiril Urbonas, DevOpsNess, updated 2026-10-31)

KU

Kiril Urbonas

Founder & Chief Editor

586 articles
View all articles by Kiril Urbonas

You might have missed

Evergreen posts worth revisiting.