| title | Better Stack |
|---|---|
| meta_desc | Provides an overview of the Better Stack provider for Pulumi. |
| layout | package |
The Better Stack provider manages Better Stack resources with Pulumi. One provider and one global API token cover uptime monitors, heartbeats, on-call calendars and escalation policies, status pages, log and metric sources, collectors, dashboards, error tracking, and Cloud's servers, networking, storage, managed services and Kubernetes.
The provider is available as a package in these languages:
- JavaScript/TypeScript:
@better_stack/pulumi - Python:
pulumi_betterstack - Go:
github.com/betterstackhq/pulumi-betterstack/sdk/go/betterstack - .NET:
BetterStack.Pulumi - Java:
com.betterstack:pulumi, packagecom.betterstack.pulumi
Pulumi downloads the provider plugin from the GitHub releases on the first pulumi up.
{{< chooser language "typescript,python,go,csharp,java,yaml" >}}
{{% choosable language typescript %}}
import * as betterstack from "@better_stack/pulumi";
const website = new betterstack.Monitor("website", {
monitorType: "status",
url: "https://example.com",
});
export const monitorId = website.id;{{% /choosable %}}
{{% choosable language python %}}
import pulumi
import pulumi_betterstack as betterstack
website = betterstack.Monitor("website",
monitor_type="status",
url="https://example.com")
pulumi.export("monitorId", website.id){{% /choosable %}}
{{% choosable language go %}}
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
})
}{{% /choosable %}}
{{% choosable language csharp %}}
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,
};
});{{% /choosable %}}
{{% choosable language java %}}
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());
});
}
}{{% /choosable %}}
{{% choosable language yaml %}}
name: betterstack-example
runtime: yaml
resources:
website:
type: betterstack:index/monitor:Monitor
properties:
monitorType: status
url: https://example.com
outputs:
monitorId: ${website.id}{{% /choosable %}}
{{< /chooser >}}
Monitors, heartbeats, sources and some other resources start with deletion protection on, so pulumi destroy stops at them until you set the deletionProtection input to false and run pulumi up. Go and C# name it DeletionProtection, and Python deletion_protection.
The provider creates Cloud resources in the zone set in betterstack:availabilityZone:
pulumi config set betterstack:availabilityZone us-west-2aA Cloud resource needs its own teamId, even when betterstack:teamId is set. This firewall allows SSH and HTTPS from anywhere. Pass web.id in a server's firewallIds to attach it:
{{< chooser language "typescript,python,yaml" >}}
{{% choosable language typescript %}}
import * as betterstack from "@better_stack/pulumi";
const web = new betterstack.Firewall("web", { teamId: "t123", name: "web" });
for (const [name, port] of [["ssh", 22], ["https", 443]] as const) {
new betterstack.FirewallRule(name, {
firewallId: web.id,
direction: "inbound",
protocol: "tcp",
ipAddresses: ["0.0.0.0/0", "::/0"],
portFrom: port,
});
}{{% /choosable %}}
{{% choosable language python %}}
import pulumi_betterstack as betterstack
web = betterstack.Firewall("web", team_id="t123", name="web")
for name, port in [("ssh", 22), ("https", 443)]:
betterstack.FirewallRule(name,
firewall_id=web.id,
direction="inbound",
protocol="tcp",
ip_addresses=["0.0.0.0/0", "::/0"],
port_from=port){{% /choosable %}}
{{% choosable language yaml %}}
resources:
web:
type: betterstack:index/firewall:Firewall
properties:
teamId: t123
name: web
ssh:
type: betterstack:index/firewallRule:FirewallRule
properties:
firewallId: ${web.id}
direction: inbound
protocol: tcp
ipAddresses: ["0.0.0.0/0", "::/0"]
portFrom: 22
https:
type: betterstack:index/firewallRule:FirewallRule
properties:
firewallId: ${web.id}
direction: inbound
protocol: tcp
ipAddresses: ["0.0.0.0/0", "::/0"]
portFrom: 443{{% /choosable %}}
{{< /chooser >}}
The provider needs a Better Stack API token. Use a global API token from Better Stack → API tokens → Global tokens, or a team API token from Better Stack → API tokens → Team-based tokens. Store it as a secret.
pulumi config set --secret betterstack:apiToken <your token>Or set the BETTERSTACK_API_TOKEN environment variable, which the provider reads when betterstack:apiToken isn't set.
A team API token works only with the product it was created for. An Incidents API token works with uptime monitoring, on-call, status pages, team members and roles. A Telemetry API token works with sources, collectors, dashboards, metrics and error tracking. A Cloud API token works with Cloud's servers, networking, storage, managed services and Kubernetes. Teams and ClickHouse connections need a global API token. With another product's resources, a team API token is refused with 401 Invalid Team API token, though the token itself is valid. To manage more than one product with team API tokens, create one explicit provider per product as under Several teams, and pass each resource the provider of its product.
| Setting | Description |
|---|---|
betterstack:apiToken |
Better Stack API token. Falls back to the BETTERSTACK_API_TOKEN environment variable. Secret. |
betterstack:teamId |
Selects the team when the API token can reach several. |
betterstack:apiRateBurst |
How many requests may go out at once above the rate. Defaults to twice the rate, at least 10, when set to 0. |
betterstack:apiRateLimit |
The most requests per second. Defaults to 8, and 0 turns the limit off. |
betterstack:apiRetryMax |
How many times a failed request is retried. Defaults to 4. |
betterstack:apiRetryWaitMax |
The longest wait before a retry, in seconds, also when Better Stack asks to wait longer. Defaults to 300. |
betterstack:apiRetryWaitMin |
The shortest wait before a retry, in seconds. Defaults to 10. |
betterstack:apiTimeout |
How long one request may take, in seconds. Defaults to 60, and 0 turns the timeout off. |
betterstack:availabilityZone |
The zone, such as us-west-2a. Each zone is separate, so pick the zone the resource is in. Falls back to the BETTERSTACK_AVAILABILITY_ZONE environment variable. |
The provider's betterstack:teamId is the team a resource is created in when the resource doesn't name one, written as the team's ID from Better Stack URLs, such as t123. To manage resources in several teams with one API token, set teamId on the resources that belong to another team. Changing a resource's teamId replaces it, because an object can't move to another team. Set betterstack:teamId when the API token can reach several teams, as a global API token can, or set teamId on every resource that accepts one.
import * as betterstack from "@better_stack/pulumi";
// Created in the team betterstack:teamId selects.
new betterstack.Heartbeat("nightly-backup", {
name: "Nightly backup",
period: 86400,
grace: 3600,
});
new betterstack.Heartbeat("settlement-job", {
teamId: "t456",
name: "Settlement job",
period: 3600,
grace: 600,
});To give each team its own token or settings, create one explicit provider per team and pass it in each resource's options:
import * as pulumi from "@pulumi/pulumi";
import * as betterstack from "@better_stack/pulumi";
const apiToken = new pulumi.Config("betterstack").requireSecret("apiToken");
const production = new betterstack.Provider("production", { apiToken, teamId: "t123" });
const staging = new betterstack.Provider("staging", { apiToken, teamId: "t456" });
new betterstack.Monitor("website", {
monitorType: "status",
url: "https://example.com",
}, { provider: production });
new betterstack.Monitor("website-staging", {
monitorType: "status",
url: "https://staging.example.com",
}, { provider: staging });An explicit provider doesn't read the stack's betterstack: settings, so the example passes the token on. Without apiToken, it reads BETTERSTACK_API_TOKEN.
Applications, ClickHouse instances, collectors, heartbeats, Kafka clusters, Kafka topics, Kubernetes clusters, monitors, MySQL instances, PostgreSQL databases, PostgreSQL instances, servers, sources, status pages, team members, teams, Valkey instances and volumes have a deletionProtection input, true by default.
While it is on, the provider refuses any pulumi up or pulumi destroy that would delete the object or replace it, including one that changes a create-only input such as a source's platform. To delete or replace one, set deletionProtection to false, run pulumi up, then make the change. Go and C# name the input DeletionProtection, and Python deletion_protection.
deletionProtection exists only in the provider. The setting is kept in the stack's state, and Better Stack's API never sees it, so it doesn't stop a delete made in the web app or with another tool. Pulumi's own protect resource option is separate. That option makes Pulumi refuse to delete any resource that has it, and is lifted with pulumi state unprotect. Use either or both.
To stop managing a protected object without deleting it in Better Stack, set the retainOnDelete option and remove it from the program, or run pulumi state delete <urn>.
Pulumi doesn't read Better Stack before each update. A change made in the Better Stack web app, or with another tool, shows up only after a refresh:
pulumi refreshor with pulumi up --refresh. Without it, pulumi preview compares your program with the last state Pulumi saved, not with what is live.
Every resource can be imported by its Better Stack ID, for example:
pulumi import betterstack:index/monitor:Monitor website 123456An object that belongs to another one, such as a dashboard chart, is imported by both IDs, like <dashboard_id>/12345. Each resource's page lists its import ID.