Filters
How to search
  • Plain words find names, texts and examples.
  • "two words" finds the exact phrase.
  • --name or -x finds an option.
  • #word looks only inside commands.
  • @grep finds lessons and labs that use grep.
  • Filters: cat:network · in:labs · in:notes · level:rhcsa · ch:8 · root:yes. Put ! before a word to leave it out. OR between words means one of them.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search

pulumi

Infrastructure as code in a real programming language (TypeScript, Python, Go, C#) — preview and apply like Terraform.

Level
DevOps tool
Group
Infrastructure as Code and cloud
Needs root
No
Package
pulumi

What it does

pulumi describes cloud resources with normal code: loops, functions, classes and tests. Like Terraform it keeps state, shows a preview of the changes and then applies them (up). A stack is one copy of the project (dev, staging, prod) with its own config and state.

State lives in Pulumi Cloud, or in your own backend (S3, Azure Blob, a local folder). Secrets in the config are encrypted.

How to write it

pulumi COMMAND [OPTIONS]

Main parts

Commands

new TEMPLATE
Start a project (for example azure-typescript).
preview
Show what would change.
up
Create or change the resources.
destroy
Delete all resources of the stack.
stack init|select|ls|output
Make / choose / list stacks; show outputs.
config set [--secret] KEY VALUE
Set a config value (or an encrypted secret).
refresh
Read the real state from the cloud.
import TYPE NAME ID
Bring an existing resource under Pulumi.
login [URL]
Choose the state backend (file://, s3://, azblob://).
state delete URN
Remove a resource from the state only.
cancel
Stop a running update.

Options 8

Most used

Options

-s, --stack NAME
Use this stack.
-y, --yes
Do not ask (CI).
--diff
Show a detailed diff.
--target URN
Only this resource.
--refresh
Refresh before the update.
--skip-preview
Do not show the preview first.
--non-interactive
No prompts or colours (CI).
--json
JSON output.

Examples 10

$ run as a normal user# run as root (or with sudo)

  1. 1Start a new Azure project in TypeScript

    pulumi new azure-typescript -n shop-infra
  2. 2Keep state in your own storage (no Pulumi Cloud)

    pulumi login azblob://pulumi-state
    pulumi login s3://acme-pulumi-state
  3. 3A small program (TypeScript)

    cat index.ts
    import * as resources from "@pulumi/azure-native/resources";
    import * as storage from "@pulumi/azure-native/storage";
    const rg = new resources.ResourceGroup("rg-shop");
    const sa = new storage.StorageAccount("stshop", {
      resourceGroupName: rg.name, kind: "StorageV2", sku: { name: "Standard_LRS" },
      minimumTlsVersion: "TLS1_2", allowBlobPublicAccess: false,
    });
    export const account = sa.name;
  4. 4Preview, then apply

    pulumi preview --diff
    pulumi up
  5. 5Stacks per environment

    pulumi stack init prod
    pulumi config set azure-native:location westeurope
    pulumi config set --secret dbPassword 'S3cr3t!'
  6. 6Read an output

    pulumi stack output account
  7. 7In CI without prompts

    pulumi up --stack prod --yes --non-interactive
  8. 8Find drift (changes made by hand)

    pulumi refresh --stack prod --yes
  9. 9Bring an existing resource in

    pulumi import azure-native:resources:ResourceGroup rg-old /subscriptions/SUB/resourceGroups/rg-old
  10. 10Delete a test stack completely

    pulumi destroy --stack dev --yes
    pulumi stack rm dev

Watch out

  • destroy deletes real resources. Protect important ones with protect: true.
  • Code can do anything — keep the program simple and reviewed like app code.
  • Back up the state backend; lost state means Pulumi forgets what it made.

Files

Pulumi.yaml
Project name and runtime.
Pulumi.STACK.yaml
Config of one stack (secrets encrypted).

Tips to remember

  • Terraform and OpenTofu have more jobs and examples; Pulumi is popular in teams of developers.

Exit codes

0OK.
255Error.

Full manual

This page explains the command in simple words. The original manual has every detail.

In your terminal: man pulumi