mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-30 01:08:33 +00:00
* feat(terraform): close key/team schema gaps, fix team read envelope, add import support * feat(terraform): add fallback resource/data source and key/team block resources * feat(terraform): add access group and unified access group resources and data sources * feat(terraform): add guardrail and prompt resources and data sources * feat(terraform): add agent and search tool resources and data sources * feat(terraform): add user and budget resources and data sources * feat(terraform): add tag and project resources and data sources * docs(terraform): changelog and readme for parity additions * feat(terraform): add data sources for keys, teams, models, organizations, and mcp servers * fix(terraform): key update 400 on empty budget_duration, key info envelope, config-supplied key * fix(terraform): hash raw keys to SHA-256 tokens in key lookup URLs and block resource IDs
71 lines
2.1 KiB
Go
71 lines
2.1 KiB
Go
package litellm
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
|
|
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
|
|
)
|
|
|
|
func dataSourceLiteLLMFallback() *schema.Resource {
|
|
return &schema.Resource{
|
|
Read: dataSourceLiteLLMFallbackRead,
|
|
|
|
Schema: map[string]*schema.Schema{
|
|
"model": {
|
|
Type: schema.TypeString,
|
|
Required: true,
|
|
Description: "The model name to get fallbacks for",
|
|
},
|
|
"fallback_type": {
|
|
Type: schema.TypeString,
|
|
Optional: true,
|
|
Default: "general",
|
|
ValidateFunc: validation.StringInSlice([]string{"general", "context_window", "content_policy"}, false),
|
|
Description: "Type of fallback: 'general' (default), 'context_window', or 'content_policy'",
|
|
},
|
|
"fallback_models": {
|
|
Type: schema.TypeList,
|
|
Computed: true,
|
|
Elem: &schema.Schema{Type: schema.TypeString},
|
|
Description: "List of fallback model names in order of priority",
|
|
},
|
|
},
|
|
}
|
|
}
|
|
|
|
func dataSourceLiteLLMFallbackRead(d *schema.ResourceData, m interface{}) error {
|
|
client := m.(*Client)
|
|
model := d.Get("model").(string)
|
|
fallbackType := GetStringValue(d.Get("fallback_type").(string), "general")
|
|
|
|
endpoint := fmt.Sprintf("/fallback/%s?fallback_type=%s", url.PathEscape(model), url.QueryEscape(fallbackType))
|
|
resp, err := MakeRequest(client, "GET", endpoint, nil)
|
|
if err != nil {
|
|
return fmt.Errorf("failed to read fallback: %w", err)
|
|
}
|
|
defer resp.Body.Close()
|
|
|
|
if resp.StatusCode == http.StatusNotFound {
|
|
return fmt.Errorf("no %s fallbacks configured for model '%s'", fallbackType, model)
|
|
}
|
|
|
|
if err := handleResponse(resp, "reading fallback"); err != nil {
|
|
return err
|
|
}
|
|
|
|
var fallbackResp FallbackGetResponse
|
|
if err := json.NewDecoder(resp.Body).Decode(&fallbackResp); err != nil {
|
|
return fmt.Errorf("error decoding fallback response: %w", err)
|
|
}
|
|
|
|
d.SetId(model)
|
|
d.Set("model", GetStringValue(fallbackResp.Model, model))
|
|
d.Set("fallback_models", fallbackResp.FallbackModels)
|
|
d.Set("fallback_type", GetStringValue(fallbackResp.FallbackType, fallbackType))
|
|
|
|
return nil
|
|
}
|