fix(variable): stop double-escaping JSON string values in variable resource#642
Merged
mitchnielsen merged 1 commit intomainfrom Feb 24, 2026
Merged
fix(variable): stop double-escaping JSON string values in variable resource#642mitchnielsen merged 1 commit intomainfrom
mitchnielsen merged 1 commit intomainfrom
Conversation
…source getUnderlyingValue() was using .String() on tuple elements and json.Unmarshal on object .String() output, both of which produce escaped representations that get re-escaped during HTTP serialization. Replace with a recursive convertAttrValueToNative() that extracts actual values via ValueString()/ValueBool()/Attributes()/Elements(). Also removes the strconv.Unquote workaround in convertAPIValueToDynamic that was compensating for the double-quoting on the read path. Closes #641 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
parkedwards
approved these changes
Feb 24, 2026
Member
parkedwards
left a comment
There was a problem hiding this comment.
i can't help but feel like some of this is my fault
Member
Author
|
I think this was mostly me, but we got there in the end hah |
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
getUnderlyingValue()was converting Terraform types to Go types incorrectly before sending them to the API. For tuples, it called.String()on each element, which wraps strings in escaped quotes (e.g.,"foo"becomes"\"foo\""). For objects, it tried tojson.Unmarshalthe.String()output, which isn't valid JSON. Both paths caused values to get double-escaped when the HTTP client JSON-serialized the request body.This replaces the conversion logic with a recursive
convertAttrValueToNative()that uses the correct SDK accessors (ValueString(),ValueBool(),Attributes(),Elements()) to extract actual values. Also removes astrconv.Unquoteworkaround inconvertAPIValueToDynamic()that was compensating for the double-quoting on the read path.Closes #641
Upgrade note
Users who have
prefect_variableresources with tuple or object values may see a one-time plan diff after upgrading. This is expected. The previously stored values in the API contain extra escape characters from the bug, and the provider will now send the correct unescaped values. Runningterraform applywill fix the stored values. No manual intervention is needed.Session context
Traced the full data flow from Terraform schema through the resource handler to the HTTP client. The
.String()method on Terraform SDK types returns a debug/display representation with JSON quoting, not the raw value. The object case was even more broken since Terraform's.String()output isn't valid JSON at all. Thestrconv.Unquoteworkaround on the read path was a clue that something was off on the write path.🤖 Generated with Claude Code