DEV Community

Alex Spinov
Alex Spinov

Posted on

Pulumi Has a Free IaC Platform That Lets You Write Infrastructure in TypeScript

Terraform forces you to learn HCL. Pulumi lets you define infrastructure in TypeScript, Python, Go, C#, or Java — with real loops, conditions, and abstractions.

HCL vs TypeScript

# Terraform — custom language, limited abstractions
resource "aws_s3_bucket" "website" {
  bucket = "my-website-bucket"
}

resource "aws_s3_bucket_website_configuration" "website" {
  bucket = aws_s3_bucket.website.id
  index_document { suffix = "index.html" }
}
Enter fullscreen mode Exit fullscreen mode
// Pulumi — real TypeScript with full IDE support
import * as aws from "@pulumi/aws";

const bucket = new aws.s3.Bucket("website", {
  website: { indexDocument: "index.html" },
});

export const url = bucket.websiteEndpoint;
Enter fullscreen mode Exit fullscreen mode

Same result. But TypeScript gives you: autocomplete, type checking, refactoring tools, loops, functions, npm packages.

Setup

npm install -g @pulumi/pulumi
pulumi new aws-typescript
# Creates project, installs deps, configures state
Enter fullscreen mode Exit fullscreen mode

Real Programming Power

Loops

// Create 3 servers with Pulumi
const servers = [1, 2, 3].map(i =>
  new aws.ec2.Instance(`server-${i}`, {
    instanceType: "t3.micro",
    ami: "ami-0abcdef1234567890",
    tags: { Name: `web-${i}` },
  })
);
Enter fullscreen mode Exit fullscreen mode

Try doing this in Terraform — you need count or for_each with limited capabilities.

Conditionals

const isProduction = pulumi.getStack() === "production";

const db = new aws.rds.Instance("database", {
  instanceClass: isProduction ? "db.r5.xlarge" : "db.t3.micro",
  multiAz: isProduction,
  backupRetentionPeriod: isProduction ? 30 : 1,
});
Enter fullscreen mode Exit fullscreen mode

Reusable Components

class WebApp extends pulumi.ComponentResource {
  public url: pulumi.Output<string>;

  constructor(name: string, args: { domain: string; dockerImage: string }) {
    super("custom:WebApp", name);

    const cluster = new aws.ecs.Cluster(`${name}-cluster`, {}, { parent: this });
    const service = new aws.ecs.FargateService(`${name}-service`, {
      cluster: cluster.arn,
      taskDefinition: /* ... */,
    }, { parent: this });

    this.url = pulumi.interpolate`https://${args.domain}`;
  }
}

// Use it like any TypeScript class
const app = new WebApp("my-app", {
  domain: "app.example.com",
  dockerImage: "my-registry/app:latest",
});
Enter fullscreen mode Exit fullscreen mode

Multi-Cloud

Pulumi supports 150+ providers:

import * as aws from "@pulumi/aws";
import * as gcp from "@pulumi/gcp";
import * as azure from "@pulumi/azure-native";
import * as k8s from "@pulumi/kubernetes";
import * as cloudflare from "@pulumi/cloudflare";
import * as vercel from "@pulumiverse/vercel";
Enter fullscreen mode Exit fullscreen mode

Pulumi AI

pulumi ai "create an S3 bucket with CloudFront CDN and Route53 DNS"
# Generates complete TypeScript code
Enter fullscreen mode Exit fullscreen mode

Free Tier (Pulumi Cloud)

  • Unlimited resources for individuals
  • State management
  • Secrets encryption
  • Deployment history
  • Up to 200 resources (free tier)

Need infrastructure automation? I build DevOps tools and data pipelines. Email spinov001@gmail.com or check my Apify tools.

Top comments (0)