The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix(terraform): keep prior state when a virtual key update is rejected (#40512)
devin-ai-integration[bot]fb603fdb6b28
diff --git a/terraform/provider/litellm/resource_key.go b/terraform/provider/litellm/resource_key.goindex 5d8bc5667a9..3b14f7ca655 100644--- a/terraform/provider/litellm/resource_key.go+++ b/terraform/provider/litellm/resource_key.go@@ -315,6 +315,7 @@ func resourceKeyUpdate(ctx context.Context, d *schema.ResourceData, m interface{metadata, err := plannedKeyMetadata(c, d)if err != nil {+ d.Partial(true)return diag.FromErr(fmt.Errorf("error updating key: %s", err))}key.Metadata = metadatadiff --git a/terraform/provider/litellm/resource_key_test.go b/terraform/provider/litellm/resource_key_test.goindex 30108856a3a..5e6385735c6 100644--- a/terraform/provider/litellm/resource_key_test.go+++ b/terraform/provider/litellm/resource_key_test.go@@ -319,6 +319,47 @@ func TestUpdateKeyOmitsEmptyBudgetDuration(t *testing.T) {}}+func TestResourceKeyUpdateFailureKeepsPriorState(t *testing.T) {+ srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {+ w.Header().Set("Content-Type", "application/json")+ if r.URL.Path == "/key/update" {+ w.WriteHeader(http.StatusBadRequest)+ w.Write([]byte(`{"error":{"message":"Invalid budget_duration 'bad'"}}`))+ return+ }+ w.Write([]byte(`{"key":"hash-1","info":{"key_alias":"demo","models":["fake-model"]}}`))+ }))+ defer srv.Close()++ res := resourceKey()+ priorData := newKeyResourceData(t, map[string]interface{}{+ "key_alias": "demo",+ "models": []interface{}{"fake-model"},+ })+ priorData.SetId("hash-1")+ prior := priorData.State()+ config := terraform.NewResourceConfigRaw(map[string]interface{}{+ "key_alias": "demo",+ "models": []interface{}{"fake-model"},+ "budget_duration": "bad",+ })+ diff, err := res.Diff(context.Background(), prior, config, nil)+ if err != nil {+ t.Fatalf("diff failed: %v", err)+ }++ newState, diags := res.Apply(context.Background(), prior, diff, NewClient(srv.URL, "test-key", true))+ if !diags.HasError() {+ t.Fatal("apply succeeded, want the proxy's 400 surfaced as an error")+ }+ if got, ok := newState.Attributes["budget_duration"]; ok {+ t.Errorf("failed update persisted budget_duration=%q into state, want it absent", got)+ }+ if newState.Attributes["key_alias"] != "demo" {+ t.Errorf("prior key_alias lost from state: %v", newState.Attributes)+ }+}+// /key/info nests the key's fields under "info"; GetKey must unwrap that// envelope or reads map nothing back into state.func TestGetKeyUnwrapsInfoEnvelope(t *testing.T) {