This Terraform provider allows you to manage LiteLLM resources through Infrastructure as Code. It provides support for managing models, teams, team members, and API keys via the LiteLLM REST API.
- Manage LiteLLM model configurations
- Associate models with specific teams
- Create and manage teams
- Configure team members and their permissions
- Set usage limits and budgets
- Control access to specific models
- Specify model modes (e.g., completion, embedding, image generation)
- Manage API keys with fine-grained controls
- Support for reasoning effort configuration in the model resource
- Terraform >= 1.1.0 (provider protocol 6.0)
- OpenTofu >= 1.6.0
- Go >= 1.24.0 for provider development
- Tested backend: exactly LiteLLM 1.104.0
The provider's global client baseline is Terraform 1.1.0 or OpenTofu 1.6.0. Terraform 1.0 is not supported because its ignore_changes planning behavior can erase the distinction between an omitted map and an explicitly empty map before the provider receives the configuration. The optional write-only attributes litellm_key.key_wo, litellm_key.send_invite_email, litellm_user.send_invite_email, and litellm_jwt_key_mapping.key_wo require Terraform or OpenTofu 1.11.0 or later only when they are configured.
To use the LiteLLM provider in your Terraform configuration, you need to declare it in the terraform block:
terraform {
required_version = ">= 1.1.0"
required_providers {
litellm = {
source = "registry.terraform.io/ncecere/litellm"
version = ">= 2.0.1, < 3.0.0"
}
}
}
provider "litellm" {
api_base = var.litellm_api_base
api_key = var.litellm_api_key
}Run terraform init -upgrade (or tofu init -upgrade) after changing the version constraint. The published source is exactly registry.terraform.io/ncecere/litellm.
Correcting the provider binary's served address to that published source does not change protocol 6, provider or resource schemas, HCL types, state values, IDs, or import formats. Normal state created with the published ncecere/litellm source needs no migration. If development-only configuration actually recorded state under the unpublished registry.terraform.io/nicholas-cecere/litellm address, migrate it explicitly; the provider does not silently alias addresses:
terraform state replace-provider \
registry.terraform.io/nicholas-cecere/litellm \
registry.terraform.io/ncecere/litellm
# OpenTofu users can run the equivalent `tofu state replace-provider` command.Then, you can use the provider to manage LiteLLM resources. Here's an example of creating a model configuration:
resource "litellm_model" "gpt4" {
model_name = "gpt-4-proxy"
custom_llm_provider = "openai"
model_api_key = var.openai_api_key
model_api_base = "https://api.openai.com/v1"
base_model = "gpt-4"
tier = "paid"
mode = "chat"
reasoning_effort = "medium" # Optional: "low", "medium", or "high"
input_cost_per_million_tokens = 30.0
output_cost_per_million_tokens = 60.0
}For full details on the litellm_model resource, see the model resource documentation.
Here's an example of creating an API key with various options:
resource "litellm_key" "example_key" {
models = ["gpt-4", "claude-3.5-sonnet"]
allowed_routes = ["/chat/completions", "/keys/*"]
max_budget = 100.0
user_id = "user123"
team_id = "team456"
max_parallel_requests = 5
tpm_limit = 1000
rpm_limit = 60
budget_duration = "monthly"
key_alias = "prod-key-1"
duration = "30d"
metadata = {
environment = "production"
}
allowed_cache_controls = ["no-cache", "max-age=3600"]
soft_budget = 80.0
aliases = {
"gpt-4" = "gpt4"
}
config = {
default_model = "gpt-4"
}
permissions = {
can_create_keys = "true"
}
model_max_budget = {
"gpt-4" = 50.0
}
model_rpm_limit = {
"claude-3.5-sonnet" = 30
}
model_tpm_limit = {
"gpt-4" = 500
}
guardrails = ["content_filter", "token_limit"]
blocked = false
tags = ["production", "api"]
}The litellm_key resource supports the following options:
models: List of allowed models for this keyallowed_routes/allowed_passthrough_routes: Restrict which LiteLLM proxy routes this key may callmax_budget: Maximum budget for the keyuser_idandteam_id: Associate the key with a user and teamservice_account_id: Create a team-owned service account key (defaultskey_aliasand injects metadata)max_parallel_requests: Limit concurrent requeststpm_limitandrpm_limit: Set tokens and requests per minute limitsbudget_duration: Specify budget duration (e.g., "monthly", "weekly")key_alias: Set a friendly name for the keyduration: Set the key's validity periodmetadata: Add custom metadata to the keyallowed_cache_controls: Specify allowed cache control directivessoft_budget: Set a soft budget limitaliases: Define model aliasesconfig: Set configuration optionspermissions: Specify key permissionsmodel_max_budget,model_rpm_limit,model_tpm_limit: Set per-model limitsguardrails: Apply specific guardrails to the keyblocked: Flag to block/unblock the keytags: Add tags for organization and filtering
When team_id is set and models is omitted, the provider automatically allows the key to use all models in that team by sending ["all-team-models"] to the API.
For full details on the litellm_key resource, see the key resource documentation.
litellm_model: Manage model configurations. Documentationlitellm_key: Manage API keys. Documentationlitellm_key_block: Block/unblock an API key. Documentationlitellm_team: Manage teams. Documentationlitellm_team_block: Block/unblock a team. Documentationlitellm_team_member: Manage an individual team member. Documentationlitellm_team_member_add: Manage a batch of team members. Documentationlitellm_organization: Manage organizations. Documentationlitellm_organization_member: Manage organization members. Documentationlitellm_project: Manage projects (between teams and keys in the hierarchy). Documentationlitellm_user: Manage users. Documentationlitellm_budget: Manage reusable budgets and rate limits. Documentationlitellm_tag: Manage tags for categorizing resources. Documentationlitellm_access_group: Manage model access groups. Documentationlitellm_unified_access_group: Manage access groups via the/v1/access_groupAPI. Documentationlitellm_fallback: Manage model fallback configuration. Documentationlitellm_guardrail: Manage content-safety guardrails. Documentationlitellm_prompt: Manage reusable prompt templates. Documentationlitellm_agent: Manage LiteLLM Agents (A2A). Documentationlitellm_search_tool: Manage web-search tool configurations. Documentationlitellm_mcp_server: Manage MCP (Model Context Protocol) servers. Documentationlitellm_credential: Manage credentials for secure authentication. Documentationlitellm_vector_store: Manage vector stores for embeddings and RAG. Documentationlitellm_jwt_key_mapping: Manage JWT string claim-to-existing-virtual-key mappings. Documentation
Single-item lookups:
litellm_model(docs),litellm_key(docs),litellm_team(docs),litellm_organization(docs),litellm_project(docs),litellm_user(docs),litellm_budget(docs),litellm_tag(docs),litellm_access_group(docs),litellm_unified_access_group(docs),litellm_prompt(docs),litellm_guardrail(docs),litellm_agent(docs),litellm_search_tool(docs),litellm_fallback(docs),litellm_mcp_server(docs),litellm_credential(docs),litellm_vector_store(docs),litellm_jwt_key_mapping(docs)
List data sources (return all items of a type):
litellm_models(docs),litellm_keys(docs),litellm_teams(docs),litellm_organizations(docs),litellm_projects(docs),litellm_users(docs),litellm_budgets(docs),litellm_tags(docs),litellm_access_groups(docs),litellm_unified_access_groups(docs),litellm_prompts(docs),litellm_guardrails(docs),litellm_agents(docs),litellm_search_tools(docs),litellm_mcp_servers(docs),litellm_jwt_key_mappings(docs)
The project is organized as follows:
terraform-provider-litellm/
├── internal/
│ └── provider/ # the provider implementation (registered in main.go)
│ ├── provider.go # provider schema + resource/data-source registration
│ ├── client.go # LiteLLM API HTTP client
│ ├── resource_*.go # resource implementations and helpers
│ ├── datasource_*.go # data-source implementations and helpers
│ └── *_test.go # unit tests
├── docs/ # resource & data-source documentation
├── internal_testing/ # docker compose LiteLLM + smoke-test configs
├── main.go # provider entrypoint
├── go.mod
├── go.sum
├── Makefile
└── ...
This repository publishes a Terraform provider binary and its HCL interface; it
is not a supported external Go library API. Provider implementation packages are
internal details. The binary entry point in main.go serves only the Terraform
Plugin Framework implementation in internal/provider.
The former top-level litellm/ Terraform Plugin SDKv2 implementation was left
behind by the Framework migration and was never registered by the migrated
provider binary. Removing that dead implementation does not require a state
migration: the provider type name, registered resource and data-source type
names, schema versions and types, state values and IDs, and import formats are
unchanged. Provider source identity and the one development-only migration case
are documented in Using the Provider.
The checked LiteLLM OpenAPI, hidden-route supplement, provider-operation golden, exact operation classification, separately reviewed pins, and offline Go verifier protect the provider's HTTP API boundary without adding any runtime Python or source dependency. See API contract maintenance for reproduction, upgrade review, and FastAPI/Pydantic limitations.
- Clone the repository:
git clone https://github.com/ncecere/terraform-provider-litellm.git- Enter the repository directory:
cd terraform-provider-litellm- Build and install the provider:
make installThe historical Go module identifier is retained for provider-build compatibility. This repository is distributed as a Terraform provider executable and does not expose a supported Go library API. Use registry.terraform.io/ncecere/litellm in Terraform or OpenTofu configurations rather than importing the Go module.
The Makefile provides several useful commands for development:
make build: Builds the providermake install: Builds and installs the providermake test: Runs the test suitemake fmt: Formats the codemake vet: Runs go vetmake contract-check: Verifies the checked LiteLLM API contract offlinemake contract-update: Regenerates the contract from the exact pinned upstream sourcemake contract-diff: Reproduces and compares the pinned contract without modifying filesmake contract-update-atomicity-test: Verifies exclusive-writer locking plus rollback, permissions, signal/failure cleanup, concurrent interleavings, and stale-lock refusalmake lint: Runs golangci-lintmake clean: Removes build artifacts and installed provider
Unit tests
make testSmoke tests (manual run against a local LiteLLM proxy) exercise real plan/apply/destroy for selected resources and data sources. Results are written to timestamped files under internal_testing/.smoke-logs/.
-
Start the proxy and DB:
make local(runsdocker compose up -dininternal_testing/). -
Optionally follow logs:
make logs. -
Run smoke for one or more files (at least one of
resources=ordatasources=required, comma-separated):make smoke resources=model_minimal.tf make smoke datasources=keys_list.tf make smoke resources=model_minimal.tf,key_minimal.tf datasources=keys_list.tf,model.tf
All listed files are applied in a single Terraform run (shared state). The harness builds the provider and copies its checked local test variables into an isolated private workspace.
-
Inspect the timestamped private log under
internal_testing/.smoke-logs/.
See internal_testing/README.md for full details (Docker layout, directory structure, tfvars).
Contributions are welcome! Please read our contributing guidelines first.
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
- Always use environment variables or secure secret management solutions to handle sensitive information like API keys and AWS credentials.
- Refer to the comprehensive documentation in the
docs/directory for detailed usage examples and configuration options. - Make sure to keep your provider version updated for the latest features and bug fixes.
- The provider now supports AWS cross-account access with
aws_session_nameandaws_role_nameparameters in the model resource. - All example configurations have been consolidated into the documentation for better organization and maintenance.