mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-15 23:31:29 +00:00
fix(credential): adopt existing credential on name conflict instead of failing
credential_name is the natural key. If a credential with that name already exists, take ownership and update it to match the configured values rather than erroring on the unique-constraint conflict. Fixes https://github.com/BerriAI/terraform-provider-litellm/issues/8
This commit is contained in:
parent
c8635ecc67
commit
155ab58e28
1 changed files with 10 additions and 0 deletions
|
|
@ -88,6 +88,16 @@ func resourceLiteLLMCredentialCreate(d *schema.ResourceData, m interface{}) erro
|
|||
|
||||
err = handleCredentialAPIResponse(resp, nil, client)
|
||||
if err != nil {
|
||||
// If a credential with this name already exists, adopt it instead of
|
||||
// failing. credential_name is the natural key, so we take ownership
|
||||
// and update the existing credential to match the configured values
|
||||
// rather than erroring on the unique-constraint conflict. See
|
||||
// https://github.com/BerriAI/terraform-provider-litellm/issues/8.
|
||||
if err.Error() == "credential_conflict" {
|
||||
log.Printf("[WARN] Credential %q already exists; adopting it and updating to match configuration.", credentialName)
|
||||
d.SetId(credentialName)
|
||||
return resourceLiteLLMCredentialUpdate(d, m)
|
||||
}
|
||||
return fmt.Errorf("failed to create credential: %w", err)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue