Skip to content

Commit 6d3f15c

Browse files
authored
support 155 (#2397)
* support 155 * leave old path as it was * fixup
1 parent d9fb45b commit 6d3f15c

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

taco/internal/tfe/workspaces.go

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -952,21 +952,32 @@ func (h *TfeHandler) CreateStateVersion(c echo.Context) error {
952952
// For direct upload without JSON wrapper, handle as raw state data
953953
return h.CreateStateVersionDirect(c, workspaceID, stateID, bodyBytes)
954954
}
955-
fmt.Printf("CreateStateVersion: Parsed JSON request: %+v\n", request)
956955

957-
// Extract the actual state data from the request
956+
// Extract the actual state data from the request (if available)
958957
data, ok := request["data"].(map[string]interface{})
959958
if !ok {
960959
fmt.Printf("CreateStateVersion: ERROR - Invalid request format, missing data\n")
961960
return c.JSON(400, map[string]string{"error": "Invalid request format"})
962961
}
963-
964-
attributes, ok := data["attributes"].(map[string]interface{})
962+
attributes, _ := data["attributes"].(map[string]any)
965963
if !ok {
966964
fmt.Printf("CreateStateVersion: ERROR - Invalid request format, missing attributes\n")
967965
return c.JSON(400, map[string]string{"error": "Invalid request format"})
968966
}
969967

968+
// INLINE STATE (Terraform <=1.5.x path) ------ upload directly in this case
969+
if enc, ok := attributes["state"].(string); ok && enc != "" {
970+
// 1) Decode inline JSON state
971+
stateBytes, decErr := base64.StdEncoding.DecodeString(enc)
972+
if decErr != nil {
973+
return c.JSON(http.StatusBadRequest, map[string]string{"error": "invalid base64 in json-state"})
974+
}
975+
fmt.Printf("CreateStateVersion: found state b64 bytes in JSON, treating as direct upload\n")
976+
// For direct upload without JSON wrapper, handle as raw state data
977+
return h.CreateStateVersionDirect(c, workspaceID, stateID, stateBytes)
978+
}
979+
980+
970981
// Look for the actual state content - it might be base64 encoded or in a specific field
971982
if jsonStateOutputs, exists := attributes["json-state-outputs"]; exists {
972983
fmt.Printf("CreateStateVersion: Found json-state-outputs field\n")

0 commit comments

Comments
 (0)