Skip to content

fix(terraform): add soft_budget, tags, and soft_budget_alerting_emails to litellm_team - #37918

Merged
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
autofix-team-soft-budget-tags
Aug 24, 2026
Merged

fix(terraform): add soft_budget, tags, and soft_budget_alerting_emails to litellm_team#37918
yuneng-berri merged 2 commits into
litellm_internal_stagingfrom
autofix-team-soft-budget-tags

Conversation

@yuneng-berri

@yuneng-berri yuneng-berri commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • litellm_team in the Terraform provider has no soft_budget or tags attributes
  • metadata is string-only, so soft_budget_alerting_emails (a list) can't be set
  • Any of those in HCL fails plan with "An argument named ... is not expected here"
  • /team/new and /team/update already accept all three

How it solves it:

  • Add soft_budget, tags, soft_budget_alerting_emails to the team schema
  • Send them on create/update; alert emails go under metadata where the proxy reads them
  • Read now decodes the team_info envelope /team/info actually returns
  • Tags / alert emails are split back out of the proxy's metadata on read
  • Removing tags / soft_budget from HCL clears them on the proxy

User Flow

Before: a platform engineer managing teams with Terraform cannot set a soft budget, tags, or alert recipients on a team, and the proxy's soft-budget alerts for that team never fire

  1. They add soft_budget = 600.0, tags = [...], and soft_budget_alerting_emails = [...] to a resource "litellm_team" block
  2. They run terraform plan and get Error: Unsupported argument — An argument named "soft_budget" is not expected here (same for tags and soft_budget_alerting_emails)
  3. They fall back to POST https://litellm-domain/team/update by hand with {"team_id": "...", "soft_budget": 600.0, "tags": [...]}, outside Terraform
  4. On the next terraform plan nothing is reported, because the provider never reads team attributes back from GET https://litellm-domain/team/info

After: the same HCL applies, lands on the proxy, and stays in sync

  1. They add soft_budget = 600.0, tags = [...], and soft_budget_alerting_emails = [...] to the same resource "litellm_team" block
  2. terraform plan accepts the configuration and shows the three attributes in the planned create/update
  3. terraform apply sends them on POST https://litellm-domain/team/new (or /team/update); GET https://litellm-domain/team/info?team_id=... returns "soft_budget": 600.0 and "metadata": {"tags": [...], "soft_budget_alerting_emails": [...], ...}
  4. A second terraform plan reports No changes; a value changed outside Terraform now shows up as drift on the next plan

Relevant issues

Pylon #7469

Linear ticket

Resolves LIT-5708

Pre-Submission checklist

  • I have added meaningful tests
  • The handful of test files covering my change pass locally: cd terraform/provider && go test -timeout 120s ./...
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review

Screenshots / Proof of Fix

Provider built from the branch and loaded through dev_overrides; OpenTofu 1.12.6 against a proxy on localhost:4080 with an isolated Postgres. Shared HCL:

resource "litellm_team" "t" {
  team_alias      = "autofix-bug2"
  models          = ["claude-haiku-4-5"]
  max_budget      = 750.0
  soft_budget     = 600.0
  budget_duration = "30d"
  tpm_limit       = 100000
  rpm_limit       = 500
  tags            = ["team:customer-insights", "environment:production"]
  soft_budget_alerting_emails = ["finops@example.com"]
  metadata = { department = "customer-insights" }
}

Before (3ac339c)

Plan with soft_budget / tags / alert emails

  1. tofu plan -no-color -input=false
  2. Observed:
    Error: Unsupported argument
      on main.tf line 5, in resource "litellm_team" "t":
    An argument named "soft_budget" is not expected here.
    Error: Unsupported argument
      on main.tf line 9, in resource "litellm_team" "t":
    An argument named "tags" is not expected here.
    Error: Unsupported argument
      on main.tf line 10, in resource "litellm_team" "t":
    An argument named "soft_budget_alerting_emails" is not expected here.
    

Apply, then read back from the proxy

  1. tofu apply -auto-approve — fails with the same three Unsupported argument errors; no team is created

Remove the attributes from HCL

  1. Not reachable (the attributes can never be applied)

soft_budget cleared outside Terraform

  1. Not reachable (the attribute can never be applied)

After (d96ce4e)

Plan with soft_budget / tags / alert emails

  1. tofu plan -no-color -input=false
  2. Observed: Plan: 1 to add, 0 to change, 0 to destroy.

Apply, then read back from the proxy

  1. tofu apply -auto-approve
    litellm_team.t: Creating...
    litellm_team.t: Creation complete after 0s [id=a6a10857-2ddf-4be5-9ca7-3ba36eebcbfc]
    Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
    
  2. curl -s "http://localhost:4080/team/info?team_id=a6a10857-..." -H "Authorization: Bearer sk-1234" | jq -c '.team_info | {soft_budget,max_budget,metadata}'
    {"soft_budget":600.0,"max_budget":750.0,"metadata":{"tags":["team:customer-insights","environment:production"],"department":"customer-insights","soft_budget_alerting_emails":["finops@example.com"]}}
  3. tofu show -json | jq -c '.values.root_module.resources[0].values | {soft_budget,tags,soft_budget_alerting_emails,metadata}'
    {"soft_budget":600,"tags":["team:customer-insights","environment:production"],"soft_budget_alerting_emails":["finops@example.com"],"metadata":{"department":"customer-insights"}}
  4. tofu plan -detailed-exitcodeNo changes. Your infrastructure matches the configuration. (exit 0)
  5. Change HCL to soft_budget = 650.0, tags = ["team:customer-insights", "environment:staging"]; tofu apply -auto-approveResources: 0 added, 1 changed, 0 destroyed.
  6. Same curl on /team/info:
    {"soft_budget":650.0,"metadata":{"tags":["team:customer-insights","environment:staging"],"department":"customer-insights","soft_budget_alerting_emails":["finops@example.com"]}}

Remove the attributes from HCL

  1. Delete soft_budget, tags, soft_budget_alerting_emails from the block; tofu apply -auto-approve0 added, 1 changed, 0 destroyed
  2. Same curl on /team/info:
    {"soft_budget":null,"metadata":{"tags":[],"department":"eng"}}
  3. tofu plan -detailed-exitcodeNo changes. Your infrastructure matches the configuration.

soft_budget cleared outside Terraform

  1. Apply a team with max_budget = 750.0, soft_budget = 600.0
  2. curl -X POST http://localhost:4080/team/update -H "Authorization: Bearer sk-1234" -d '{"team_id":"...","soft_budget":null}'; /team/info now returns "soft_budget": null
  3. tofu plan -detailed-exitcode → exit 2, ~ soft_budget = 0 -> 600, Plan: 0 to add, 1 to change, 0 to destroy.

Also verified on both commits (pass before and after): the pre-existing attribute set applies, matches /team/info, re-plans clean, updates, and destroys; a minimal team_alias-only team re-plans clean; litellm_key still round-trips soft_budget + tags.

Type

🐛 Bug Fix

Caveats (if any)

  • Read previously never refreshed any team attribute from the proxy (wrong envelope); now all of them do
  • metadata stays string-only: Terraform SDK v2 has no list-valued map elements, hence the dedicated attribute
  • litellm_team has no Importer even though the docs describe terraform import; pre-existing, not touched here

…s to litellm_team

The team resource rejected soft_budget and tags at plan time and had no way
to express the list-valued metadata.soft_budget_alerting_emails the proxy
reads for soft-budget alerts, even though /team/new and /team/update accept
all three. Add the attributes, forward them in buildTeamData (alert emails
merged under metadata, where the proxy stores them), and send the full
metadata map whenever either half changes because /team/update replaces
metadata wholesale.

Read was decoding /team/info as if the team fields were top-level, but the
proxy nests them under team_info, so every attribute silently fell back to
prior state. Decode the envelope and split the proxy's metadata back into
tags / soft_budget_alerting_emails / string metadata, dropping the
server-managed team_member_budget_id.

Verified with OpenTofu plan/apply against a live proxy: the attributes are
accepted, land on the proxy, refresh into state, re-plan clean, propagate
on update, and clear when removed from HCL.
@greptile-apps

greptile-apps Bot commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR adds Terraform support for team soft budgets, tags, and alert recipients while correcting team-info response decoding and state refresh behavior.

  • Adds the new team resource schema fields and maps them through create, update, and read operations.
  • Separates tags and alert recipients from general string metadata during state synchronization.
  • Adds regression coverage for create, update, response-envelope decoding, attribute removal, and null soft-budget refreshes.
  • Updates the Terraform provider documentation and changelog.

Confidence Score: 5/5

The PR appears safe to merge.

No blocking failure remains.

Important Files Changed

Filename Overview
terraform/provider/litellm/resource_team.go Adds schema and payload/state mappings for the new team attributes and now clears soft_budget state when the proxy returns null.
terraform/provider/litellm/resource_team_test.go Adds focused tests for team creation, response-envelope decoding, removed attributes, and null soft-budget refresh behavior.
terraform/provider/litellm/types.go Adds the team-info response envelope and nullable soft-budget response field.
terraform/provider/docs/resources/team.md Documents the newly supported Terraform team attributes.
terraform/provider/CHANGELOG.md Records the added attributes and corrected team-info state refresh.

Reviews (2): Last reviewed commit: "fix(terraform): clear litellm_team.soft_..." | Re-trigger Greptile

Comment thread terraform/provider/litellm/resource_team.go Outdated
Comment thread terraform/provider/litellm/resource_team.go
Comment thread terraform/provider/litellm/resource_team.go
@codecov

codecov Bot commented Aug 22, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

…y returns null

Read only wrote soft_budget when the proxy returned a value, so a soft
budget cleared outside Terraform stayed in state and never surfaced as
drift. Set it from the response unconditionally so a null clears it.
@yuneng-berri

Copy link
Copy Markdown
Contributor Author

@greptileai

@yuneng-berri
yuneng-berri enabled auto-merge (squash) August 23, 2026 05:37
@yuneng-berri
yuneng-berri merged commit a72203e into litellm_internal_staging Aug 24, 2026
72 checks passed
@yuneng-berri
yuneng-berri deleted the autofix-team-soft-budget-tags branch August 24, 2026 17:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants