DEV Community

Alex Spinov
Alex Spinov

Posted on

Pulumi Has a Free API: Infrastructure as Real Code, Not YAML

Terraform is HCL. CloudFormation is YAML. CDK generates JSON. Pulumi is actual TypeScript/Python/Go — with loops, conditions, and real abstractions.

What Is Pulumi?

Pulumi is an infrastructure-as-code platform where you define cloud resources in real programming languages — TypeScript, Python, Go, C#, Java, YAML.

import * as pulumi from "@pulumi/pulumi"
import * as aws from "@pulumi/aws"

// Create a VPC
const vpc = new aws.ec2.Vpc("my-vpc", { cidrBlock: "10.0.0.0/16" })

// Create subnets in a loop (try THIS in Terraform)
const subnets = ["10.0.1.0/24", "10.0.2.0/24", "10.0.3.0/24"].map((cidr, i) =>
  new aws.ec2.Subnet(\`subnet-\${i}\`, {
    vpcId: vpc.id,
    cidrBlock: cidr,
    availabilityZone: \`us-east-1\${String.fromCharCode(97 + i)}\`,
  })
)

// S3 bucket
const bucket = new aws.s3.Bucket("my-bucket", {
  versioning: { enabled: true },
})

// Lambda function
const fn = new aws.lambda.Function("my-function", {
  runtime: "nodejs20.x",
  handler: "index.handler",
  code: new pulumi.asset.FileArchive("./lambda"),
  environment: {
    variables: { BUCKET_NAME: bucket.id },
  },
})

// Export outputs
export const bucketUrl = bucket.websiteEndpoint
export const functionArn = fn.arn
Enter fullscreen mode Exit fullscreen mode

Why Pulumi Over Terraform

1. Real language features:

// Conditional resources
if (config.requireBoolean("enableMonitoring")) {
  new aws.cloudwatch.Dashboard("monitoring", { /* ... */ })
}

// Reusable components
class MyDatabase extends pulumi.ComponentResource {
  public readonly connectionString: pulumi.Output<string>

  constructor(name: string, args: DatabaseArgs) {
    super("custom:MyDatabase", name)
    const rds = new aws.rds.Instance(\`\${name}-rds\`, { /* ... */ })
    this.connectionString = rds.endpoint
  }
}
Enter fullscreen mode Exit fullscreen mode

2. IDE support — autocomplete, type checking, refactoring. Not possible with HCL.

3. Testing:

import { expect } from "chai"
import * as pulumi from "@pulumi/pulumi"

describe("infrastructure", () => {
  it("bucket should have versioning", async () => {
    const versioning = await bucket.versioning.get()
    expect(versioning?.enabled).to.be.true
  })
})
Enter fullscreen mode Exit fullscreen mode

4. Multi-cloud — AWS, Azure, GCP, Kubernetes, 150+ providers with same language.

Free Tier

Pulumi Cloud: free for individual use (unlimited stacks, 200 resources).

pulumi new aws-typescript
pulumi up
Enter fullscreen mode Exit fullscreen mode

Building cloud infrastructure? Check out my developer tools or email spinov001@gmail.com.

Top comments (0)