Skip to content

fix(terraform): mark litellm_key partial when /key/update rejects the request - #40522

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
litellm_fix_terraform_key_partial_state_on_update_error
Draft

cursor[bot] wants to merge 1 commit into
mainfrom
litellm_fix_terraform_key_partial_state_on_update_error

Conversation

@cursor

@cursor cursor Bot commented Sep 10, 2026

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • A rejected /key/update still persisted the bad planned values into Terraform state, so the next terraform plan showed no drift and the update was silently dropped
  • TestResourceKeyUpdateFailureKeepsPriorState (added in fix(terraform): keep prior state when a virtual key update is rejected #40512) started failing on litellm_internal_staging after the merge landed the guard in the wrong branch

How it solves it:

  • Call d.Partial(true) in the c.UpdateKey error path too, not only on plannedKeyMetadata failures

User Flow

Before: a Terraform user who typos budget_duration = "bad" on a litellm_key sees the apply fail and then loses the guard on retries

  1. They run terraform apply on a litellm_key with budget_duration = "bad"
  2. The proxy 400s with Invalid budget_duration 'bad' and the apply fails
  3. They fix the typo to budget_duration = "30d" and run terraform plan again
  4. The plan reports no changes, the key on the proxy still has no budget_duration set, and the fix is silently dropped

After: the same user's retry actually applies the corrected value

  1. They run terraform apply on a litellm_key with budget_duration = "bad"
  2. The proxy 400s with Invalid budget_duration 'bad' and the apply fails
  3. They fix the typo to budget_duration = "30d" and run terraform plan again
  4. The plan shows budget_duration changing from "" to "30d" and the next apply pushes it to the proxy

Relevant issues

Linear ticket

Pre-Submission checklist

Screenshots / Proof of Fix

Before (5264f8e)

  1. cd terraform/provider && go test -timeout 60s -run TestResourceKeyUpdateFailureKeepsPriorState ./...
  2. Output:
    --- FAIL: TestResourceKeyUpdateFailureKeepsPriorState (0.00s)
        resource_key_test.go:356: failed update persisted budget_duration="bad" into state, want it absent
    FAIL	github.com/BerriAI/terraform-provider-litellm/litellm	0.007s
    

After (ff8e0f8)

  1. cd terraform/provider && go test -timeout 120s ./...
  2. Output:
    ?   	github.com/BerriAI/terraform-provider-litellm	[no test files]
    ok  	github.com/BerriAI/terraform-provider-litellm/litellm	5.079s
    ok  	github.com/BerriAI/terraform-provider-litellm/tools/endpointaudit	0.003s
    

Type

🐛 Bug Fix

Final Attestation

  • The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
Open in Web View Automation 

… request

Only the plannedKeyMetadata error path was calling d.Partial(true).
When /key/update itself returned an error (e.g. 400 on Invalid
budget_duration), the SDK still persisted the rejected planned values
into state, so the next plan reported no changes and silently dropped
the update. TestResourceKeyUpdateFailureKeepsPriorState caught this on
litellm_internal_staging.

Co-authored-by: Krrish Dholakia <krrish-berri-2@users.noreply.github.com>
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@yuneng-berri
yuneng-berri deleted the branch main September 13, 2026 04:51
@yuneng-berri yuneng-berri reopened this Sep 13, 2026
@devin-ai-integration
devin-ai-integration Bot changed the base branch from litellm_internal_staging to main September 23, 2026 14:37

This branch has not been deployed

No deployments
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.

3 participants