Pulumi

Manage your Better Stack resources as code with Pulumi. One provider covers monitors, heartbeats, on-call, escalation policies, status pages, sources, collectors, dashboards, error tracking and the rest of the Better Stack API, in TypeScript, Python, Go, C#, Java or YAML. Every resource is on the Pulumi Registry.

Install the provider

Add the package for your language to your Pulumi project:

TypeScript Python Go C#
npm install @better_stack/pulumi
pip install pulumi-betterstack
go get github.com/betterstackhq/pulumi-betterstack/sdk/go/betterstack
dotnet add package BetterStack.Pulumi

For Java, add com.betterstack:pulumi from Maven Central. A YAML program needs no package.

Set your API token

Store a global API token as a secret:

Set the API token
pulumi config set --secret betterstack:apiToken $TOKEN


The provider also reads the BETTERSTACK_API_TOKEN environment variable. When your token can reach more than one team, set the team the provider creates resources in:

Set the team
pulumi config set betterstack:teamId t123

Create a resource

TypeScript Python Go C# Java YAML
import * as betterstack from "@better_stack/pulumi";

const website = new betterstack.Monitor("website", {
    monitorType: "status",
    url: "https://example.com",
});

export const monitorId = website.id;
import pulumi
import pulumi_betterstack as betterstack

website = betterstack.Monitor("website",
    monitor_type="status",
    url="https://example.com")

pulumi.export("monitorId", website.id)
package main

import (
	"github.com/betterstackhq/pulumi-betterstack/sdk/go/betterstack"
	"github.com/pulumi/pulumi/sdk/v3/go/pulumi"
)

func main() {
	pulumi.Run(func(ctx *pulumi.Context) error {
		website, err := betterstack.NewMonitor(ctx, "website", &betterstack.MonitorArgs{
			MonitorType: pulumi.String("status"),
			Url:         pulumi.String("https://example.com"),
		})
		if err != nil {
			return err
		}
		ctx.Export("monitorId", website.ID())
		return nil
	})
}
using System.Collections.Generic;
using Pulumi;
using BetterStack = Pulumi.BetterStack;

return await Deployment.RunAsync(() =>
{
    var website = new BetterStack.Monitor("website", new()
    {
        MonitorType = "status",
        Url = "https://example.com",
    });

    return new Dictionary<string, object?>
    {
        ["monitorId"] = website.Id,
    };
});
package myproject;

import com.pulumi.Pulumi;
import com.betterstack.pulumi.Monitor;
import com.betterstack.pulumi.MonitorArgs;

public class App {
    public static void main(String[] args) {
        Pulumi.run(ctx -> {
            var website = new Monitor("website", MonitorArgs.builder()
                .monitorType("status")
                .url("https://example.com")
                .build());

            ctx.export("monitorId", website.id());
        });
    }
}
name: betterstack-example
runtime: yaml
resources:
  website:
    type: betterstack:index/monitor:Monitor
    properties:
      monitorType: status
      url: https://example.com
outputs:
  monitorId: ${website.id}

Run pulumi up to create the monitor.

View all Pulumi resources

The Pulumi Registry lists every resource and function with its inputs and outputs.

Import existing resources

Bring a resource you created in Better Stack under Pulumi with its ID:

Import a monitor
pulumi import betterstack:index/monitor:Monitor website 123456

To pick up changes made in Better Stack, refresh the stack's state before the update with pulumi up --refresh. To refresh before every operation, set it in your Pulumi.yaml:

Pulumi.yaml
options:
  refresh: always