Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Jul 9, 2024
1 parent 2e51d5b commit 96b4abd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 16 deletions.
26 changes: 11 additions & 15 deletions common/reflect_resource_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,38 +68,34 @@ func tfSdkToGoSdkSingleField(srcField reflect.Value, destField reflect.Value, sr
return err
}
} else if srcField.Kind() == reflect.Struct {
switch srcFieldValue.(type) {
switch v := srcFieldValue.(type) {
case types.Bool:
boolVal := srcFieldValue.(types.Bool)
destField.SetBool(boolVal.ValueBool())
if !boolVal.IsNull() {
destField.SetBool(v.ValueBool())
if !v.IsNull() {
addToForceSendFields(srcFieldName, forceSendFieldsField)
}
case types.Int64:
intVal := srcFieldValue.(types.Int64)
destField.SetInt(intVal.ValueInt64())
if !intVal.IsNull() {
destField.SetInt(v.ValueInt64())
if !v.IsNull() {
addToForceSendFields(srcFieldName, forceSendFieldsField)
}
case types.Float64:
floatVal := srcFieldValue.(types.Float64)
destField.SetFloat(floatVal.ValueFloat64())
if !floatVal.IsNull() {
destField.SetFloat(v.ValueFloat64())
if !v.IsNull() {
addToForceSendFields(srcFieldName, forceSendFieldsField)
}
case types.String:
strVal := srcFieldValue.(types.String)
destField.SetString(strVal.ValueString())
if !strVal.IsNull() {
destField.SetString(v.ValueString())
if !v.IsNull() {
addToForceSendFields(srcFieldName, forceSendFieldsField)
}
case types.List:
diag := srcFieldValue.(types.List).ElementsAs(ctx, destField.Addr().Interface(), false)
diag := v.ElementsAs(ctx, destField.Addr().Interface(), false)
if len(diag) != 0 {
panic("Error")
}
case types.Map:
srcFieldValue.(types.Map).ElementsAs(ctx, destField.Addr().Interface(), false)
v.ElementsAs(ctx, destField.Addr().Interface(), false)
default:
// If it is a real stuct instead of a tfsdk type, recursively resolve it.
if err := TfSdkToGoSdkStruct(srcFieldValue, destField.Addr().Interface(), ctx); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion common/reflect_resource_plugin_framework_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ func TestStructConversion(t *testing.T) {

// Convert the gosdk struct back to tfsdk struct
convertedTfSdkStruct := DummyTfSdk{}
e = GoSdkToTfSdk(convertedGoSdkStruct, &convertedTfSdkStruct, ctx)
e = GoSdkToTfSdkStruct(convertedGoSdkStruct, &convertedTfSdkStruct, ctx)
assert.NoError(t, e)

// Assert that the struct is exactly the same after tfsdk --> gosdk --> tfsdk
Expand Down

0 comments on commit 96b4abd

Please sign in to comment.