Manage LiteLLM with the Terraform provider
The LiteLLM Terraform provider manages teams, virtual keys, models, and other resources through a running gateway's API. Use it after you deploy the gateway. To create cloud infrastructure, see the Terraform deployment guide.
Configure the provider
Declare the provider in main.tf:
terraform {
required_providers {
litellm = {
source = "BerriAI/litellm"
version = "1.104.9" # Example: replace with your gateway's version.
}
}
}
provider "litellm" {}
Provider releases follow LiteLLM versions. Pin the provider to the version your gateway runs. See the provider version guidance and published versions.
Set the gateway URL and a LiteLLM API key with permission to manage your resources. The provider reads both values from environment variables. Load the key from your CI secret store to keep it out of your Terraform files.
export LITELLM_API_BASE="https://llm.example.com"
export LITELLM_API_KEY="<your-management-api-key>"
Connect the gateway to its database. Make sure the machine that runs Terraform can reach the gateway.
Create a team
Add this resource to main.tf to create a team named development-team.
resource "litellm_team" "development" {
team_alias = "development-team"
}
Install the provider, review the proposed change, and apply it:
terraform init
terraform plan
terraform apply
The team appears in the Admin UI under Teams. Change the resource in Terraform to update its configuration. See the team resource reference to set model access, budgets, rate limits, and permissions.
Manage an existing team
Add a matching resource block, then import the team's ID from LiteLLM:
terraform import litellm_team.development '<team-id>'
terraform plan
Use the team ID, which can differ from its display name. Review the plan and update your configuration before the next apply.
The provider reference lists supported resources and data sources, including virtual keys, models, users, and MCP servers. Find the provider source and development instructions in BerriAI/litellm.