Managing LiteLLM keys, teams and models with Terraform

The LiteLLM Terraform provider lets platform teams declare gateway models, teams, keys and MCP servers in version control. This page covers what it manages, how it fits with Admin UI changes, and what to confirm before adopting it.

On this page

Why teams manage LiteLLM keys and models with Terraform

Teams manage LiteLLM keys and models with Terraform when they need every change to the gateway to be reviewed, repeatable and traceable. A platform team running a shared LiteLLM gateway typically handles many requests for new keys, team budget changes, model additions and rotations. Clicking through the Admin UI makes each change fast but leaves little record of who approved it, what the previous value was, or whether a staging gateway matches production. The LiteLLM Terraform provider, published under the registry source BerriAI/litellm, lets those objects live in version control and go through the same pull request review as the rest of the infrastructure. The provider documentation lists the resources available.

The provider covers litellm_model, litellm_team, litellm_team_member, litellm_key, litellm_mcp_server, litellm_credential, litellm_vector_store and litellm_jwt_key_mapping. Together these describe which upstream models exist, how teams and their members are organized, which virtual keys belong to which team and what they may call, and how identity tokens map to keys. Teams usually need this when the number of teams, keys or models grows past what one person can review by hand, when several environments must match, or when an auditor asks how a key's model access was approved. For a single small gateway with a handful of stable keys, the Admin UI may be enough. Before adopting the provider, confirm with your team which objects you will manage in code and which will stay in the UI, because a value changed in both places will drift.

Which resources to manage in code and which to leave in the Admin UI

This table compares each resource the LiteLLM Terraform provider can manage by what it controls, who usually owns it, and whether it fits version control. Read the last column first to see which resources suit code review, then use the rows to decide where changes should originate. The main takeaway is that model definitions depend on the store_model_in_db setting, which decides whether a model added in the Admin UI can drift from your code.

ResourceWhat it controlsUsual owner and version control fit
Models (litellm_model)Provider model entries, upstream routes and cost settings that callers request by namePlatform team. Strong fit for code, but only if store_model_in_db is set so changes are not overwritten or hidden in the database
Teams (litellm_team)Team identity, budgets, model access and rate limits for a group of usersPlatform or FinOps team. Good fit for code, since budgets and limits are reviewed like other financial settings
Team members (litellm_team_member)Which users belong to a team and their role within itTeam leads or identity administrators. Fits code when membership follows an approved onboarding process, otherwise it changes often
Keys (litellm_key)Virtual keys, their budgets, model restrictions and limits for a service or personPlatform team for service keys. Keys are sensitive, so confirm how generated key values are stored and who can read Terraform state
MCP servers (litellm_mcp_server)Registered MCP server endpoints and their access settings for agents and toolsPlatform or security team. Good fit for code, because each registration grants tools reachable from the gateway
Credentials (litellm_credential)Upstream provider credentials used by models and serversSecurity or platform team. Fits code only with a secret manager or encrypted variables, since plain values end up in state
Vector stores (litellm_vector_store)Vector store connections available through the gatewayData or platform team. Fits code when the store and its access policy are documented alongside the resource
JWT key mappings (litellm_jwt_key_mapping)How identity provider token claims map to keys or teamsIdentity team. Fits code and should be reviewed with the SSO design, since mistakes change who gets access

How store_model_in_db and Admin UI edits interact with Terraform

When every model is declared in the proxy config file, that file is the source of truth for models. Terraform cannot manage models as database records in this setup, so the team should confirm whether litellm_model resources can be created at all with store_model_in_db off in their LiteLLM version. Keys, teams and team members still live in the database, so the provider can manage those even when models come from the file.

  • Source of truth: the model_list in the config file, deployed through your normal change process, such as a Git commit followed by a redeploy.
  • Admin UI edits: model changes made in the UI are expected to be unavailable or to revert on restart. Confirm this behavior for your version.
  • Drift on the next plan: Terraform has no model resources to compare, so model changes made outside the file do not appear in a plan.
  • Key and team drift: these objects are stored in the database and do show up in plans, even though models come from the file.
  • Single owner per model: each model name should have exactly one place where it is defined.

Check that the config file and the Terraform code have a clear owner for every model name before the first apply.

Setting up the LiteLLM provider with state and review

This sequence moves LiteLLM gateway configuration into version-controlled code with a pinned provider, separate state per environment, and a reviewed path from plan to apply. The result is a repeatable workflow where every change to keys, teams and models is visible before it reaches the gateway.

  1. Pin the provider version

    The platform engineer selects the LiteLLM provider from the registry source BerriAI/litellm and pins an exact version in the root module's required_providers block, then commits the lock file generated by the first initialization. Pinning matters because the provider's resource schemas change between releases, and an unpinned provider can produce plan changes nobody asked for. Confirm the chosen provider version against the LiteLLM release line your gateway runs, and check the provider documentation for the resources you plan to manage. Done when init completes cleanly and the lock file is in source control.

  2. Configure the provider with a secret-managed master key

    Set the provider's gateway URL and master key so that the key is read from your secret manager at run time, not written into a .tf file or a variable file committed to the repository. The master key must match the LITELLM_MASTER_KEY your proxy uses, and it must start with sk-. In CI, inject it from the pipeline's secret store, and for local runs use a short-lived session that fetches it from the same vault. Check that a grep of the repository and the plan output returns no key value. Done when a read-only call such as a plan succeeds against a non-production gateway without the key appearing in logs.

  3. Split state by environment

    Create a separate state file and backend location for each environment, such as development, staging and production, so a change tested in one gateway cannot touch another by accident. Each environment gets its own root configuration pointing at its own gateway URL and its own key, and the backend must have access control and encryption at rest. State holds sensitive values from keys and credentials, so restrict who can read it and treat it like a secret store. Confirm by running plan in each environment and checking that the target URL in each output matches the intended gateway. Done when no environment can plan against another environment's gateway.

  4. Import existing teams and keys

    Most gateways already have teams, members and virtual keys created through the Admin UI or API, so declare those resources in code and import the live objects into state rather than creating duplicates. Use the import mechanism for each resource type the provider supports, and record the identifiers in a reviewed change. Virtual key values are not something you should copy into code, so import by identifier and let the gateway hold the secret material. Confirm the import by running plan and checking that it shows no unexpected changes for the imported resources. Any diff needs a decision: either update the code to match the live object or accept the change in a reviewed apply.

  5. Confirm the plan shows no unexpected changes

    After import, run a full plan against each environment and read every proposed change before anything else happens. A clean baseline means the code describes the gateway as it is today, and any remaining diff is either an intended change or a configuration drift that needs investigation. Pay particular attention to fields the Admin UI or other tools may set, such as budgets, rate limits and model access lists, because changes made outside code will be reverted on the next apply. Record the baseline plan output as the reference for later reviews. Done when two consecutive plans with no code changes both report no changes.

  6. Run plan in CI with review

    Configure the pipeline so every pull request runs format checks, validation and a plan for the affected environment, and posts the plan output for review. Reviewers check the resource names, the keys being created or deleted, model access changes and any change to budgets or rate limits, and approve only the plans they understand. Restrict who can merge to the main branch and who can approve production plans, and keep the master key out of plan artifacts that other people can download. Done when a sample change produces a visible plan comment that a second person has approved.

  7. Apply the approved plan

    Apply only the plan that was reviewed, ideally by running apply from the saved plan file produced in the review step, so that the applied change matches what the approver saw. Apply to development first, then staging, then production, and confirm after each apply that the gateway reflects the change by testing a request with the affected key or model. Keep a record of who approved each apply and link it to the pull request. Done when the applied change is visible on the gateway and the state file reflects the new object.

  8. Check for drift after each apply

    After every production apply, run a scheduled plan that compares the gateway with the code and reports any difference, which catches changes made through the Admin UI or API after the last apply. Decide a policy for drift in advance: either the pipeline reports it for a human to resolve, or the team agrees that code is the only source of truth and changes outside it are reverted. Confirm the policy with the people who use the Admin UI for day-to-day work, because a strict policy changes how they operate. Done when a deliberate change made in the Admin UI shows up in the scheduled plan.

How Terraform changes reach the gateway

The flow starts with an engineer committing HCL to version control. CI runs a plan and then an apply with OpenTofu or Terraform, and the LiteLLM provider calls the proxy's management API. The proxy writes the resulting models, teams, keys and other objects to PostgreSQL, and the Admin UI and callers then read that same state. The Admin UI edit path sits outside the pipeline, so changes made there show up as drift on the next plan. The master key used by the provider comes from a secret manager, not from the repository.

Terraform changes and manual Admin UI edits both land in the same database.

Protecting the master key, state and keys created by code

Managing LiteLLM through Terraform concentrates administrative power in a few places: the master key, the state file and the key values that code creates. Each card below names one of those places, the risk it carries and the check to run before the configuration goes live.

Keep the master key in a secret manager

The LITELLM_MASTER_KEY grants broad administrative rights over the gateway, including creating keys, teams and models. It must start with sk- and should live in a secret manager, never in a .tf file, a variable default or a CI log. Check who can read it, which pipelines receive it at runtime, and whether the Terraform provider credentials are separate from the human admin login so each can be rotated on its own.

Production guide

Encrypt and restrict Terraform state

State can hold generated key values, credentials and provider settings in readable form. Use a remote backend with access limited to the pipeline role and the few engineers who run plans, and turn on state encryption so the file is protected at rest. Confirm which key provider your backend supports, and keep state access logs so you can see who read it.

Encryption introduced
v1.7
OpenTofu state encryption docs

Hand off generated key values securely

A litellm_key resource returns a key value that exists only once it is created. Decide before the first apply where that value goes, such as a named secret in your secret manager with a restricted reader list, and never print it as a Terraform output or send it through chat. Record who received each key so a later rotation has a clear owner.

Review budget and model access changes

Changes to max_budget, rate limits or the list of models a team can call change spend exposure directly. Require a second reviewer on pull requests that touch these attributes, and have the plan output reviewed before apply. Ask your gateway team to confirm which fields are safe to change in place and which force a key to be recreated.

Audit changes made outside Terraform

The Admin UI and API can change the same objects that Terraform manages, and a manual edit creates drift that the next apply may silently reverse or that hides a risky change. Schedule regular plans to detect drift, and check whether your gateway logs record admin actions with the actor's identity. Confirm which audit features your edition includes before you rely on them.

Choosing OpenTofu or Terraform for state and encryption

The LiteLLM Terraform provider, published under the registry source BerriAI/litellm, runs inside a standard plan and apply workflow, so the first decision is which CLI executes it. OpenTofu is an open-source option under the Mozilla Public License 2.0. Its project describes it as a drop-in replacement for Terraform that preserves existing workflows and configurations. Before you commit, confirm with the provider documentation and the OpenTofu Registry that the provider version you pin is published and tested with the CLI you choose. Provider support is not guaranteed to be identical across both tools, so record the tool and version in your pipeline definition.

State matters more for this provider than for most, because the resources manage keys, team memberships and credentials that may appear in state. OpenTofu encrypts state and plan files at rest, for local storage and remote backends, and this feature was introduced in v1.7. Its key providers include PBKDF2, AWS KMS, GCP KMS, OpenBao and Azure Vault. Ask your security team which key provider fits your cloud account and secret tooling, and confirm how the remote backend, KMS permissions and key rotation will be managed. If you stay on Terraform, confirm which native state encryption options your version offers before you assume parity.

OpenTofu is under the Linux Foundation's stewardship and was accepted to the CNCF at the Sandbox maturity level on April 23, 2025. Its v1.13.1 release is dated October 1, 2026. The OpenTofu FAQ states an aim of feature parity with Terraform, but it also says compatibility with future Terraform releases is not guaranteed. Plan for that divergence by pinning tool versions, testing upgrades in a non-production workspace and reviewing release notes before each change. The OpenTofu migration guide describes a four-step path: back up state and code, install, initialize and verify, then test with a small change. Configurations that share data through terraform_remote_state need extra care during that move.

Limits to confirm before moving gateway changes into code

The LiteLLM Terraform provider can manage a useful set of gateway objects, but it does not cover everything the Admin UI or proxy can do. Each card below is a limit to check before you move a team's keys, models or access rules under Terraform, because the gap between code and live state is where outages and surprise changes start.

Resource coverage is a fixed list

The provider manages only the listed resources: models, teams, team members, keys, MCP servers, credentials, vector stores and JWT key mappings. Any setting outside that list, such as a feature you enable in the Admin UI or a proxy configuration option, is not under Terraform control. Before you commit, map every gateway setting your team relies on to a provider resource, and record the settings that stay manual so reviewers know where the code stops.

Provider docs

Admin UI edits can overwrite code

A key rotated, a budget raised or a model added in the Admin UI can differ from what the Terraform state records. The next plan may then show a change that reverts someone's emergency fix. Decide which channel is authoritative for each resource type, restrict UI write access for managed teams, and require that any out-of-band change be copied back into code within the same working day.

Importing existing keys and teams

Gateways that already run have live keys, team members and budgets with spend history. Creating matching resources from scratch can duplicate identities or reset limits. Write an import runbook that maps each live object to its resource address, imports it into a copy of the state, and runs a plan that shows no changes before any production apply. Test the runbook on a non-production gateway first.

Provider and LiteLLM version pairing

The provider must match the gateway API your LiteLLM release exposes. LiteLLM maintains support for the four most recent stable minor versions, so a provider pinned to an older schema can fail against a gateway that has moved on. Pin both versions in your repository, check the provider changelog against the LiteLLM release you run, and upgrade the two together in a staging environment.

Supported minor versions
Four
LiteLLM releases

Generated secrets in state

Keys created by the provider return secret values that land in Terraform state, and state can also hold credential values for upstream providers. Anyone who can read the state can read those secrets. Choose a remote backend with encryption and access control, and consider OpenTofu state encryption with a managed key provider. Define who can read state, how long old state versions are kept, and how a leaked key is rotated.

State encryption docs

Questions teams ask before managing LiteLLM with Terraform

How much effort does moving LiteLLM configuration from the Admin UI to code take?

The effort depends mainly on how much configuration already exists in the Admin UI and how many teams, keys and models it covers. No duration figure is supplied for this move, so ask a partner for an estimate based on an inventory of your current objects. The main drivers are the number of models and provider credentials to recreate, how many teams and team members need mapping to owners, whether keys already in use must be preserved or reissued, and whether MCP servers and vector stores are in scope. Before estimating, export a list of what exists and decide which object types will be managed as code and which will stay manual during a transition period.

Can our own team manage LiteLLM with Terraform without outside help?

Yes, if your team already runs Terraform or OpenTofu against other platforms and has someone who can own the gateway's configuration. The LiteLLM Terraform provider is published under the registry source BerriAI/litellm and covers resources such as litellm_model, litellm_team, litellm_team_member, litellm_key and litellm_mcp_server. The harder parts are usually not the syntax but the design: deciding how state is stored and protected, how secrets reach the provider, how changes are reviewed, and how drift from Admin UI edits is handled. Outside help is most useful for the initial module design, the state and secret setup, and the first migration of live keys and budgets.

What does our organization need to provide for a Terraform-managed gateway?

You will need access to the running gateway through an administrative key or equivalent, a remote state backend with access control and encryption, a CI pipeline that runs plan and apply with reviews, and a named owner for each team and its keys. Store the LiteLLM master key, which must start with sk-, in a secret manager rather than in code. Confirm with your platform team which secret store the pipeline can read from. Owners need to approve changes to their team's models, budgets and rate limits, so agree on who signs off before the first apply. Also confirm who holds the state backend credentials and who can run apply against production.

Which state backend should we use, and how should we protect it?

Use a remote backend that your organization already audits and backs up, and enable encryption for state and plan files. OpenTofu encrypts state and plan files at rest for local storage and remote backends, with key providers including PBKDF2, AWS KMS, GCP KMS, OpenBao and Azure Vault, and the feature is tagged as introduced in v1.7. Terraform state for this provider can contain sensitive values such as generated key material, so restrict read access to the pipeline and a small set of administrators. Confirm with your security team which key provider fits your cloud and whether state versioning and locking are available on your chosen backend.

Does managing LiteLLM with Terraform change the license or support terms?

Using Terraform or OpenTofu does not change LiteLLM's license. LiteLLM is dual licensed: content under the enterprise/ directory uses the license in enterprise/LICENSE, and everything else is under the MIT license, according to the BerriAI/litellm LICENSE file. Enterprise features are a separate matter. SSO for the Admin UI is free for up to 5 users from v1.76.0, and an Enterprise license is needed beyond that. Features such as SCIM, JWT authentication, audit logs and team-level guardrails are Enterprise features, so confirm with LiteLLM which edition covers the objects you plan to manage. Support terms also come from LiteLLM's own Enterprise agreement, not from this implementation work.

How should we plan upgrades of the LiteLLM proxy and the Terraform provider together?

Pin both the proxy image and the provider version in code, and upgrade them in a deliberate order that you test in a non-production gateway first. LiteLLM maintains support for the four most recent stable minor versions for both open source and Enterprise deployments, so plan upgrades inside that window. The latest release listed on the LiteLLM releases page at the time of research is v1.105.1, published October 14, 2026. Check the provider's changelog for resource schema changes before bumping the provider, and run plan against a copy of production state. Confirm with your partner or LiteLLM which proxy versions a given provider release supports.

What happens if someone still edits keys or models in the Admin UI?

Changes made in the Admin UI will appear as drift the next time you plan, and a plain apply may revert them. Decide early which object types are managed as code and enforce that with a policy, such as limiting Admin UI write access to break-glass administrators who log their changes and then sync them back into code. The store_model_in_db setting determines whether models are kept in the gateway database, which affects how Admin UI and code-managed models interact, so confirm its behavior for your proxy version before you start. Test a deliberate UI edit against a non-production gateway to see how drift appears in your plan output.

Can OpenTofu replace Terraform for this configuration?

OpenTofu is designed as a drop-in replacement for Terraform that preserves existing workflows and configurations, and it is licensed under the Mozilla Public License 2.0. OpenTofu was accepted to the CNCF on April 23, 2025 at the Sandbox maturity level, and v1.13.1 was released on October 1, 2026. Its FAQ states an aim of feature parity with Terraform but does not guarantee compatibility with future Terraform releases. Before choosing, confirm that the LiteLLM provider works with the OpenTofu version you plan to run, and follow the migration steps of backing up state, installing, initializing and verifying, and testing with a small change.

How DeployOpen scopes Terraform-managed LiteLLM gateways

DeployOpen scopes a Terraform-managed LiteLLM gateway as a fixed-scope, written engagement. DeployOpen is a Chainscore Labs company. It plans, implements, hardens and documents self-hosted open-source platforms inside the client's own cloud accounts, data centers or restricted networks. For a LiteLLM gateway, the written scope names the resources that will be code-managed (models, teams, team members, keys, MCP servers, credentials and vector stores), the Terraform provider version to be pinned, and which settings stay in the Admin UI or under the store_model_in_db decision. Deliverables and acceptance checks are agreed before work starts, so both sides know what "done" means for the configuration repository.

Scoping also covers the layout of code and state. The team decides how many state files exist, how they are split by environment and team, where remote state lives, how state is encrypted, and who holds apply rights to each workspace. Virtual key values, the LITELLM_MASTER_KEY and provider credentials must stay out of plain-text variables and state, so the scope should name the secret manager that holds them. Confirm with your security team which state backend and encryption approach you require before the first apply, because changing it later means migrating state.

Retainers cover the work that follows the first build. A gateway configured as code still needs provider version upgrades, LiteLLM release line upgrades, drift review when someone edits settings in the Admin UI, and updates when teams or models change. DeployOpen offers these as ongoing retainers, scoped in writing like the initial build. Ask any partner, including DeployOpen, to state in the agreement who owns the repository, who runs terraform plan on each change, and how the handover of operational knowledge to your engineers will be documented.

Sources and further reading

Talk to our team.

Tell us what you're working on, whether it's a deployment, an audit, a security test or a cyber range. You'll speak with an engineer who can help you scope it.

  • 30-minute call: free, with no obligation.
  • NDA on request: we can sign before you share details.
  • Clear next steps: a scope and plan after the call.