fix: handle key recreation when team_id changes or key is cascade deleted#24
Open
shin-bot-litellm wants to merge 1 commit intoBerriAI:mainfrom
Open
Conversation
…eted Related to BerriAI#12 - Recreate flow reuses deleted resource IDs after team update When a team is updated with changes to immutable fields (like team_alias), Terraform destroys and recreates the team. Keys associated with the old team may be cascade deleted in LiteLLM, causing subsequent key updates to fail. Changes: 1. Added ForceNew: true to team_id field in key resource schema - When team_id changes, the key will be recreated instead of updated - This ensures a clean state when teams are recreated 2. Added graceful handling in resourceKeyUpdate for missing keys - Detects 'does not exist' / 'not found' / 'invalid user key' errors - Clears the resource ID so Terraform recreates the key - Returns a warning diagnostic instead of failing This allows the recreate flow to complete successfully: 1. Old team deleted → Old keys cascade deleted 2. New team created 3. Key update fails (key gone) → Key marked for recreation 4. New key created with new team_id
Member
|
@greptile can you review this? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Related to #12 - Recreate flow reuses deleted resource IDs after team update
Problem
When a team is updated with changes to immutable fields (like
team_alias), Terraform destroys and recreates the team. Keys associated with the old team may be cascade deleted in LiteLLM, causing subsequent key updates to fail with:Solution
1. ForceNew on team_id
Added
ForceNew: trueto theteam_idfield in the key resource schema. Whenteam_idchanges, the key will be recreated instead of updated, ensuring a clean state.2. Graceful Missing Key Handling
Added error detection in
resourceKeyUpdatethat:New Behavior
When a team is recreated:
Note on Breaking Change
Adding
ForceNew: truetoteam_idmeans that changing a key's team association will now require key recreation instead of in-place update. This is the safer behavior since: