From 155ab58e28b1704677aa89c753fae210ca9442a3 Mon Sep 17 00:00:00 2001 From: Matthew Howard <78384492+matthowardcohere@users.noreply.github.com> Date: Fri, 4 Sep 2026 09:39:07 -0400 Subject: [PATCH] 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 --- terraform/provider/litellm/resource_credential_crud.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/terraform/provider/litellm/resource_credential_crud.go b/terraform/provider/litellm/resource_credential_crud.go index dd9aef64f76..ace0d97d5a0 100644 --- a/terraform/provider/litellm/resource_credential_crud.go +++ b/terraform/provider/litellm/resource_credential_crud.go @@ -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) }