Manage Cloud with Pulumi

Manage your Cloud servers, firewalls and SSH keys as code with Pulumi.

Install the provider

TypeScript Python
npm install @better_stack/pulumi
pip install pulumi-betterstack

Pulumi downloads the provider plugin on your first pulumi up.

Configure the provider

Create a global API token in Settings → API tokens → Global tokens. Store it as a secret when Pulumi asks for it, and set the data center your resources are in:

Configure your stack
pulumi config set --secret betterstack:apiToken
pulumi config set betterstack:availabilityZone us-west-2a

Create your first server

Add your SSH key, a firewall that lets in SSH and HTTPS, and a server that uses both. Replace t123 with your team's ID from betterstack team list in the Cloud CLI:

TypeScript Python
import * as fs from "fs";
import * as os from "os";
import * as betterstack from "@better_stack/pulumi";

const teamId = "t123";

const key = new betterstack.SshKey("laptop", {
    teamId,
    slug: "my-laptop",
    publicKey: fs.readFileSync(`${os.homedir()}/.ssh/id_ed25519.pub`, "utf8"),
});

const firewall = new betterstack.Firewall("web", { teamId, name: "web" });

for (const [name, port] of [["ssh", 22], ["https", 443]] as const) {
    new betterstack.FirewallRule(name, {
        firewallId: firewall.id,
        direction: "inbound",
        protocol: "tcp",
        ipAddresses: ["0.0.0.0/0", "::/0"],
        portFrom: port,
    });
}

const server = new betterstack.Server("web", {
    teamId,
    name: "web-1",
    serverType: "AM1",
    image: "ubuntu-26-04",
    sshKeys: [key.slug],
    firewallIds: [firewall.id],
});

export const serverIp = server.ipAddresses.apply(addresses => addresses.find(a => a.type === "ipv4")!.ip);
import os
import pulumi
import pulumi_betterstack as betterstack

team_id = "t123"

key = betterstack.SshKey("laptop",
    team_id=team_id,
    slug="my-laptop",
    public_key=open(os.path.expanduser("~/.ssh/id_ed25519.pub")).read())

firewall = betterstack.Firewall("web", team_id=team_id, name="web")

for name, port in [("ssh", 22), ("https", 443)]:
    betterstack.FirewallRule(name,
        firewall_id=firewall.id,
        direction="inbound",
        protocol="tcp",
        ip_addresses=["0.0.0.0/0", "::/0"],
        port_from=port)

server = betterstack.Server("web",
    team_id=team_id,
    name="web-1",
    server_type="AM1",
    image="ubuntu-26-04",
    ssh_keys=[key.slug],
    firewall_ids=[firewall.id])

pulumi.export("serverIp", server.ip_addresses.apply(
    lambda addresses: next(a.ip for a in addresses if a.type == "ipv4")))
Create the server
pulumi up

Connect as root:

Connect to the server
ssh root@$(pulumi stack output serverIp)

A firewall created this way has no inbound rules of its own, so keep the SSH rule to reach the server.

Removing a server?

Servers start with deletionProtection on. To remove one with pulumi destroy, set deletionProtection: false and run pulumi up first.

Need help?

Please let us know at hello@betterstack.com.
We're happy to help! 🙏