Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"TypedSDK": Fix the issue with the removedInNextMajorVersion tag causing data loss in Decode #23564

Merged
merged 1 commit into from
Oct 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions internal/sdk/resource_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package sdk
import (
"fmt"
"reflect"
"strings"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand Down Expand Up @@ -57,6 +58,7 @@ func decodeReflectedType(input interface{}, stateRetriever stateRetriever, debug
debugLogger.Infof("Field", field)

if val, exists := field.Tag.Lookup("tfschema"); exists {
val = strings.TrimSuffix(val, ",removedInNextMajorVersion")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine for now, but I think we want to add a parseStructTag method which returns a struct to ultimately solve this - however I'm going to do that in a separate PR since that also needs to be handled in the Set too.

tfschemaValue, valExists := stateRetriever.GetOkExists(val)
if !valExists {
continue
Expand Down Expand Up @@ -192,6 +194,7 @@ func setListValue(input interface{}, index int, fieldName string, v []interface{
debugLogger.Infof("nestedField ", nestedField)

if val, exists := nestedField.Tag.Lookup("tfschema"); exists {
val = strings.TrimSuffix(val, ",removedInNextMajorVersion")
nestedTFSchemaValue := test[val]
if err := setValue(elem.Interface(), nestedTFSchemaValue, j, fieldName, debugLogger); err != nil {
return err
Expand Down
Loading