A Terraform provider for managing Langfuse resources programmatically.
Langfuse is an open-source LLM engineering platform that provides observability, analytics, prompt management, and evaluations for LLM applications. This provider allows you to manage organizations, projects, and API keys using Infrastructure as Code (IaC) principles.
- π’ Organization Management - Create and manage Langfuse organizations
- π API Key Management - Generate and manage organization and project API keys
- π¦ Project Management - Create and configure projects within organizations
- π€ LLM Connections Management - Configure and manage LLM API connections (OpenAI, Bedrock, Vertex AI, etc.)
- π‘οΈ Enterprise Support - Full support for Langfuse Enterprise features
- β‘ Terraform Integration - Native integration with Terraform workflows
- Terraform >= 1.5
- Go >= 1.24 (for development)
- Enterprise license key (if managing organizations and organization api keys)
Add the provider to your Terraform configuration:
terraform {
required_providers {
langfuse = {
source = "langfuse/langfuse"
version = "~> 0.1.0"
}
}
}For development and testing:
# Clone the repository
git clone https://github.com/langfuse/terraform-provider-langfuse
cd terraform-provider-langfuse
# Build the provider
go build -o terraform-provider-langfuse
provider "langfuse" {
host = "https://cloud.langfuse.com" # Optional, defaults to https://app.langfuse.com
admin_api_key = var.admin_api_key # Optional, can use LANGFUSE_ADMIN_KEY env var
}LANGFUSE_ADMIN_KEY- Admin API key (alternative toadmin_api_key)LANGFUSE_EE_LICENSE_KEY- Enterprise license key (required for admin operations)
terraform {
required_providers {
langfuse = {
source = "langfuse/langfuse"
version = "~> 0.1.0"
}
}
}
# Variables for configuration
variable "host" {
type = string
description = "Base URL of the Langfuse control plane"
default = "https://cloud.langfuse.com"
}
variable "admin_api_key" {
type = string
sensitive = true
description = "Admin API key for Langfuse (or set LANGFUSE_ADMIN_KEY)"
}
# Configure the provider
provider "langfuse" {
host = var.host
admin_api_key = var.admin_api_key
}
# Create an organization
resource "langfuse_organization" "example" {
name = "My Organization"
}
# Create organization API keys
resource "langfuse_organization_api_key" "example" {
organization_id = langfuse_organization.example.id
}
# Create a project within the organization
resource "langfuse_project" "example" {
name = "my-project"
organization_id = langfuse_organization.example.id
retention_days = 90 # Optional: data retention period
organization_public_key = langfuse_organization_api_key.example.public_key
organization_private_key = langfuse_organization_api_key.example.secret_key
}
# Create project API keys
resource "langfuse_project_api_key" "example" {
project_id = langfuse_project.example.id
organization_public_key = langfuse_organization_api_key.example.public_key
organization_private_key = langfuse_organization_api_key.example.secret_key
}
# Output the API keys (marked as sensitive)
output "org_public_key" {
value = langfuse_organization_api_key.example.public_key
sensitive = true
}
output "project_secret_key" {
value = langfuse_project_api_key.example.secret_key
sensitive = true
}Manages Langfuse organizations.
name(String, Required) - The display name of the organization
id(String) - The unique identifier of the organization
Manages API keys for organizations.
organization_id(String, Required) - The ID of the organization
id(String) - The unique identifier of the API keypublic_key(String, Sensitive) - The public API key valuesecret_key(String, Sensitive) - The secret API key value
Note: API key values are only returned during creation and cannot be retrieved later.
Manages projects within organizations.
name(String, Required) - The display name of the projectorganization_id(String, Required) - The ID of the parent organizationorganization_public_key(String, Required, Sensitive) - Organization public key for authenticationorganization_private_key(String, Required, Sensitive) - Organization private key for authenticationretention_days(Number, Optional) - Data retention period in days. If not set or 0, data is stored indefinitely
id(String) - The unique identifier of the project
Manages API keys for projects.
project_id(String, Required) - The ID of the projectorganization_public_key(String, Required, Sensitive) - Organization public key for authenticationorganization_private_key(String, Required, Sensitive) - Organization private key for authentication
id(String) - The unique identifier of the API keypublic_key(String, Sensitive) - The public API key valuesecret_key(String, Sensitive) - The secret API key value
Manages organization membership - invites users to organizations and manages their roles. This resource automatically creates users in the Langfuse system via the SCIM endpoint if they don't already exist.
email(String, Required, ForceNew) - The email address of the user to add to the organizationrole(String, Required) - The role to assign to the user. Valid values:OWNER,ADMIN,MEMBER,VIEWERorNONEorganization_public_key(String, Required, Sensitive, ForceNew) - Organization public key for authenticationorganization_private_key(String, Required, Sensitive, ForceNew) - Organization private key for authentication
id(String) - The unique identifier of the membershipuser_id(String) - The unique identifier of the userstatus(String) - The status of the membership (e.g., "ACTIVE")username(String) - The username of the user
- Automatic User Creation: If the user doesn't exist in the organization, the resource automatically creates them using the SCIM endpoint before adding them to the organization
- Role Updates: The role can be updated after creation using Terraform
applywith the updated role value - Deletion: When the resource is destroyed, the user is removed from the organization (but not deleted from the Langfuse system)
- Resource ID: The resource ID is set to the user's
userIdfrom the Langfuse system, which uniquely identifies the membership within the organization
# Create organization membership with automatic user creation
resource "langfuse_organization_membership" "engineer" {
email = "engineer@example.com"
role = "MEMBER"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_key
}
# Update user role
resource "langfuse_organization_membership" "admin" {
email = "admin@example.com"
role = "ADMIN"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_key
}
# Multiple users in organization
resource "langfuse_organization_membership" "team" {
for_each = toset([
"dev1@example.com",
"dev2@example.com",
"qa@example.com"
])
email = each.value
role = "MEMBER"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_key
}Manages project membership - adds users to projects and manages their project-level roles. Users must already exist in the organization before being added to a project.
project_id(String, Required, ForceNew) - The ID of the project to add the user toemail(String, Required, ForceNew) - The email address of the user to add to the projectrole(String, Required) - The role to assign to the user. Valid values:OWNER,ADMIN,MEMBER,VIEWERorNONEorganization_public_key(String, Required, Sensitive, ForceNew) - Organization public key for authenticationorganization_private_key(String, Required, Sensitive, ForceNew) - Organization private key for authentication
id(String) - The unique identifier of the project membershipuser_id(String) - The unique identifier of the username(String) - The name of the user
- Role Updates: The role can be updated after creation using Terraform
applywith the updated role value - Deletion: When the resource is destroyed, the user is removed from the project (but not from the organization)
- Import Format:
project_id,user_id,organization_public_key,organization_private_key
# Add a user to a project as admin
resource "langfuse_project_membership" "admin" {
project_id = langfuse_project.project.id
email = "admin@example.com"
role = "ADMIN"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_key
}
# Add a user to a project as member
resource "langfuse_project_membership" "member" {
project_id = langfuse_project.project.id
email = "member@example.com"
role = "MEMBER"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_key
}
# Add multiple users to a project
resource "langfuse_project_membership" "team" {
for_each = toset([
"dev1@example.com",
"dev2@example.com",
"qa@example.com"
])
project_id = langfuse_project.project.id
email = each.value
role = "MEMBER"
organization_public_key = langfuse_organization_api_key.org_key.public_key
organization_private_key = langfuse_organization_api_key.org_key.secret_keyManages LLM API connections for a Langfuse project. Supports OpenAI, Bedrock, Azure, Google Vertex AI, and custom providers. Each connection is uniquely identified by its provider name. Connections are upserted (created or updated) via the provider name; destroying the resource deletes the connection from Langfuse.
project_public_key(String, Required, Sensitive) - Project public key for authenticationproject_secret_key(String, Required, Sensitive) - Project secret key for authenticationprovider_name(String, Required, ForceNew) - Unique name for the LLM connection within the project. Changing this value destroys and recreates the resource.adapter(String, Required) - LLM adapter type. Valid values:anthropic,openai,azure,bedrock,google-vertex-ai,google-ai-studiosecret_key(String, Required, Sensitive) - API key for the LLM providerbase_url(String, Optional) - Custom base URL for the LLM APIcustom_models(List of String, Optional) - List of custom model namesextra_headers(Map of String, Optional, Sensitive) - Additional HTTP headers for LLM API requestswith_default_models(Bool, Optional, Computed) - Whether to include default models (defaults to true)config(String, Optional) - Adapter-specific configuration as a JSON string
id(String) - The unique identifier (UUID) of the LLM connectionadapter(String) - The LLM adapter typeprovider_name(String) - The provider namebase_url(String) - The base URL usedcustom_models(List of String) - Custom model nameswith_default_models(Bool) - Whether default models are includedconfig(String) - Adapter-specific config as JSONcreated_at(String) - Timestamp when the connection was createdupdated_at(String) - Timestamp when the connection was last updated
- Upsert Semantics: Creating or updating this resource always upserts the connection in Langfuse by provider name. Changing
providerdestroys and recreates the resource. - Delete: Destroying the resource calls
DELETE /api/public/llm-connections/{id}and removes the connection from Langfuse. - Write-only Fields: Sensitive fields like
secret_keyandextra_headersare preserved from the plan/state and not returned by the API. - Config Validation: Adapter-specific config requirements are enforced:
- Bedrock:
configmust be JSON with aregionkey, e.g.{ "region": "us-east-1" } - Google Vertex AI:
configmay be omitted, but if provided must include alocationkey, e.g.{ "location": "us-central1" } - Other adapters:
configmust be null or omitted
- Bedrock:
- Pagination: Read operation paginates through all LLM connections to find the target provider.
# OpenAI connection
resource "langfuse_llm_connection" "openai_prod" {
project_public_key = "your-project-public-key"
project_secret_key = "your-project-secret-key"
provider_name = "openai-prod"
adapter = "openai"
secret_key = "sk-..."
with_default_models = true
}
# Bedrock connection with custom config
resource "langfuse_llm_connection" "bedrock_prod" {
project_public_key = "your-project-public-key"
project_secret_key = "your-project-secret-key"
provider_name = "bedrock-prod"
adapter = "bedrock"
secret_key = "AK..."
base_url = "https://bedrock.aws.example.com"
custom_models = ["my-bedrock-model"]
config = jsonencode({ region = "us-east-1" })
with_default_models = false
}
# Google Vertex AI connection
resource "langfuse_llm_connection" "vertex_ai_prod" {
project_public_key = "your-project-public-key"
project_secret_key = "your-project-secret-key"
provider_name = "vertex-ai-prod"
adapter = "google-vertex-ai"
secret_key = "vertex-key"
config = jsonencode({ location = "us-central1" })
with_default_models = true
}
# Azure connection
resource "langfuse_llm_connection" "azure_prod" {
project_public_key = "your-project-public-key"
project_secret_key = "your-project-secret-key"
provider_name = "azure-prod"
adapter = "azure"
secret_key = "azure-key"
with_default_models = true
}
# Custom provider with extra headers
resource "langfuse_llm_connection" "my_gateway" {
project_public_key = "your-project-public-key"
project_secret_key = "your-project-secret-key"
provider_name = "my-gateway"
adapter = "openai"
secret_key = "sk-custom"
extra_headers = {
"X-My-Header" = "custom-value"
}
with_default_models = true
}-
Clone the repository:
git clone https://github.com/langfuse/terraform-provider-langfuse cd terraform-provider-langfuse -
Install dependencies:
go mod download
-
Generate mocks (for testing):
make generate
The project includes comprehensive unit and integration tests.
Run fast unit tests with mocked dependencies:
make testRun integration tests against a real Langfuse instance:
# Set required environment variable
export LANGFUSE_EE_LICENSE_KEY="your_license_key"
# Run acceptance tests (starts Docker environment)
make testacc
# Clean up test environment
make test-teardownFor detailed testing instructions, see TESTING.md.
# Build for current platform
go build -o terraform-provider-langfuse
# Build for multiple platforms
goreleaser build --snapshot --clean- Fork the repository
- Create a feature branch:
git checkout -b my-feature - Make your changes and add tests
- Run tests:
make test-all - Commit your changes:
git commit -am 'Add new feature' - Push to the branch:
git push origin my-feature - Create a Pull Request
- Follow standard Go conventions
- Use
gofmtfor formatting - Add unit tests for new functionality
- Update documentation as needed
This project is licensed under the MIT License - see the LICENSE file for details.
- π Langfuse Documentation
- π Report Issues
- π¬ Community Discussions
See CHANGELOG.md for release notes and version history.