Manage Logfire with Infrastructure as Code
Manage your Logfire projects, dashboards, alerts, and credentials with configuration files. Infrastructure as Code (IaC) lets you review and apply these changes with your application configuration.
Use the Logfire provider with Terraform or OpenTofu. The examples and resource list below come from the latest stable Terraform provider release, v0.2.3.
logfire_alertlogfire_api_keylogfire_channellogfire_dashboardlogfire_frontend_applicationlogfire_frontend_application_tokenlogfire_gateway_api_keylogfire_gateway_providerlogfire_organizationlogfire_projectlogfire_read_tokenlogfire_schedulelogfire_slologfire_write_token
Create a Logfire API key with the
scopes required by your resources.
Set LOGFIRE_API_KEY to that key in your environment.
Save this configuration as main.tf:
terraform {
required_version = ">= 1.8"
required_providers {
logfire = {
source = "registry.terraform.io/pydantic/logfire"
version = "= 0.2.3"
}
}
}
# Configure via env vars:
# export LOGFIRE_API_KEY="pylf_v1_..."
provider "logfire" {
# Optional override, mainly for self-hosted deployments:
# base_url = "https://logfire-us.pydantic.dev"
# api_key = "pylf_v1_..."
}
resource "logfire_project" "example" {
name = "example-project"
description = "Managed by Terraform"
}
Apply the configuration:
terraform init
terraform apply
tofu init
tofu apply
Review the plan before you approve it. Applying this configuration creates a project in your API key’s organization. You should see the project in Logfire after the command completes.
api_key(String, Sensitive) Bearer token. If omitted, the LOGFIRE_API_KEY environment variable is used.base_url(String) Base URL for the Logfire API. If omitted, the provider uses LOGFIRE_BASE_URL or infers the SaaS endpoint from the api_key region. Self-hosted customers should set this explicitly.custom_headers(Map of String, Sensitive) Additional HTTP headers to include on every Logfire API request. Intended for proxy, gateway, or edge authentication. Provider-managed headers cannot be overridden.
Set base_url to your self-hosted Logfire endpoint.
Check the provider’s self-hosted compatibility and credential requirements
before you apply the configuration.
Use the Pulumi Logfire package for configuration in your programming language. Its releases come from the Terraform provider, but can follow a different release schedule. See the Pulumi provider repository for its source.
For permission errors or an unavailable self-hosted API, follow the provider’s credential troubleshooting guide.