Pulumi Datadog
The `pulumi-datadog` Python package provides a way to declare, deploy, and manage Datadog resources like monitors, dashboards, and integrations using Pulumi's Infrastructure as Code framework. It mirrors the upstream Datadog Terraform Provider and typically releases new versions in sync with updates to that provider. The library is actively maintained and currently at version 5.1.0.
Warnings
- breaking Version 5.x of `pulumi-datadog` is based on version 4.x of the upstream `terraform-provider-datadog`. This major version bump in the underlying Terraform provider typically introduces breaking changes in resource properties and behaviors. Users upgrading from `pulumi-datadog` v4.x should consult the `terraform-provider-datadog` v4.0.0 changelog for a comprehensive list of changes, as these will directly impact your Pulumi code.
- gotcha The Datadog API Key (DD_API_KEY) and Application Key (DD_APP_KEY) are both required for authenticating the provider. Failure to provide both will result in authentication errors. These should be treated as sensitive secrets.
- gotcha The `apiUrl` (or `DD_HOST` environment variable) for the Datadog provider must *not* end with `/api/`. Incorrectly adding this suffix will lead to API request failures.
- gotcha Pulumi resources managed by `pulumi-datadog` can drift from their desired state if they are manually modified within the Datadog UI. This can lead to unexpected `pulumi preview` diffs or apply failures.
Install
-
pip install pulumi-datadog
Imports
- datadog
import pulumi_datadog as datadog
- Monitor
datadog.Monitor
- Provider
datadog.Provider
Quickstart
import pulumi
import pulumi_datadog as datadog
import os
# Configure Datadog API and APP keys using environment variables
# pulumi config set datadog:apiKey --secret $DD_API_KEY
# pulumi config set datadog:appKey --secret $DD_APP_KEY
# Or, set them directly as provider arguments (less secure for sensitive keys)
# provider = datadog.Provider(
# "datadog-provider",
# api_key=os.environ.get('DD_API_KEY', ''),
# app_key=os.environ.get('DD_APP_KEY', ''),
# api_url="https://api.datadoghq.com/" # Ensure no /api/ suffix
# )
# Create a Datadog monitor
example_monitor = datadog.Monitor("example-monitor",
name="Pulumi Example Host CPU Alert",
type="metric alert",
query="avg(last_5m):system.cpu.idle{*} by {host} < 10",
message="High CPU detected on {{host.name}}! @pagerduty",
tags=["environment:dev", "team:sre"],
priority=3,
monitor_thresholds=datadog.MonitorMonitorThresholdsArgs(
critical=10.0,
warning=20.0,
),
force_delete=True # Useful for development, be cautious in production
)
pulumi.export('monitor_id', example_monitor.id)
pulumi.export('monitor_name', example_monitor.name)