Skip to content

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.

Terraform and OpenTofu

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.

What you can manage

Quick start

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:

Terminal
terraform init
terraform 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.

Provider configuration

Optional

  • 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.

Self-hosted deployments

Set base_url to your self-hosted Logfire endpoint. Check the provider’s self-hosted compatibility and credential requirements before you apply the configuration.

Pulumi

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.

Troubleshooting

For permission errors or an unavailable self-hosted API, follow the provider’s credential troubleshooting guide.