fix: detect external changes and prevent version_description drift#11
Merged
roh26it merged 1 commit intoPortkey-AI:mainfrom Feb 21, 2026
Conversation
41f80d4 to
27e3017
Compare
Fixes two issues with prompt and prompt_partial resources: 1. prompt_partial: External edits (via console/API) were invisible to Terraform because mapPartialToState always preserved content from state. Now compares API version to state version — if higher, content is refreshed from API so Terraform detects drift and overwrites. 2. Both resources: version_description set via console was imported into state during Read, causing perpetual plan drift when config didn't set it. Removed API-to-state import for version_description. Adds unit tests for mapPartialToState and mapPromptToState covering drift detection, state preservation, first population, and version_description behavior.
27e3017 to
7326f1c
Compare
roh26it
approved these changes
Feb 21, 2026
Contributor
roh26it
left a comment
There was a problem hiding this comment.
Approved
Thoroughly reviewed and tested locally.
What was verified:
- Build,
go vet, andgofmtall pass - All 10 new unit tests pass
- All prompt_partial acceptance tests pass (5/5)
- The 2 failing prompt_resource tests are pre-existing failures on main branch (verified by running the same tests against main)
Code review findings:
- Drift detection logic is sound: Using version comparison (
!=) correctly detects both new versions (console edits) and rollbacks - Version lookup fix is correct: Fetching from
/versionsendpoint instead of+1increment handles version gaps caused by out-of-band changes - version_description fix prevents perpetual drift: No longer importing from API avoids the state/config mismatch cycle
- Tests are meaningful: Verify actual values, not just existence
The changes are well-documented, follow existing patterns, and fix real bugs.
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
Fixes drift detection, perpetual plan diff, and version numbering issues with
portkey_promptandportkey_prompt_partialresources.Problems Fixed
External edits invisible to Terraform — Both
mapPromptToStateandmapPartialToStatepreserved content from state during Read, ignoring API values. If someone edited a prompt or partial in the Portkey console, Terraform never detected the change.version_description perpetual drift — Both resources imported
version_descriptionfrom the API into state during Read. If set via console but not in Terraform config, this caused an infinite plan loop (state has value → config doesn't → plan nulls it → apply clears it → Read imports it again).MakeDefault targeting wrong version — After creating a new version, the provider called
MakeDefaultwithstate.Version + 1, which breaks when versions are created outside Terraform (console edits create gaps in the version sequence).How It Works
Drift detection: During
Read, both mapping functions now compare the API version to the state version:This catches both new versions (console edits) and rollbacks (console sets an older version as default). When versions match, content is preserved from state to avoid false diffs from Portkey API eventual consistency.
Version lookup: After
Updatecreates a new version, the provider calls the/versionslist endpoint, matches the returned version UUID against the update response, and gets the real version number forMakeDefault. No more guessing with+1.version_description: No longer imported from the API — only preserved from state.
Changes
client.goListPromptVersions,ListPromptPartialVersionsclient methods and response typesprompt_partial_resource.go!=), version lookup via list API, removed version_description API importprompt_resource.go!=), version lookup via list API, removed version_description API import, parameters refreshed on external changemap_state_test.go(new)Test Plan