Skip to main content

How to provision cloud infrastructure with Pulumi

Define cloud resources in TypeScript with Pulumi, organize them into stacks, and deploy with pulumi up. Covers projects, outputs, verification, and teardown.

Difficulty
Intermediate
Duration
50 minutes
Steps
6

What and why

Pulumi is an infrastructure-as-code tool that uses general-purpose languages such as TypeScript, Python, and Go instead of a domain-specific syntax. You get loops, functions, and package managers to express infrastructure. This tutorial provisions a cloud bucket in TypeScript.

Prerequisites

  • The Pulumi CLI installed.
  • A cloud account with credentials in your environment.
  • A language runtime installed (Node.js for this example).

Steps

1. Create a new project

pulumi new aws-typescript

The wizard scaffolds a project, installs dependencies, and creates your first stack.

2. Understand stacks

A stack is an isolated instance of your program, such as dev or prod. Each stack has its own state and configuration:

pulumi stack ls

3. Declare a resource in code

In index.ts:

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

const bucket = new aws.s3.Bucket("data", {
  versioning: { enabled: true },
});

Resources are class instances; their constructor arguments are the configuration.

4. Export stack outputs

export const bucketName = bucket.id;

Exported values become stack outputs you can query or feed into other stacks.

5. Deploy with pulumi up

pulumi up

Pulumi shows a preview of changes. Confirm to create the resources and record them in the stack's state.

Verification

Run pulumi stack output bucketName to read the result, and check the resource in your cloud console. Run pulumi up again; it should report no changes.

Next Steps

Use config values with pulumi config set to parameterize stacks per environment. Refactor repeated resources into a component resource. When finished, run pulumi destroy to remove everything cleanly.

Prerequisites

  • Pulumi CLI installed
  • A cloud account with credentials
  • Node.js or Python installed

Steps

  • 1
    Create a new project
  • 2
    Understand stacks
  • 3
    Declare a resource in code
  • 4
    Export stack outputs
  • 5
    Deploy with pulumi up
  • 6
    Verify and destroy