Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardfeng-db committed Jul 11, 2024
1 parent 60f0597 commit d72ed85
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions common/reflect_resource_plugin_framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"reflect"

"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
)

Expand Down Expand Up @@ -289,3 +290,25 @@ func checkTheStringInForceSendFields(fieldName string, forceSendFields []string)
}
return false
}

func pluginFrameworkTypeToSchema(v reflect.Value) map[string]schema.Attribute {
rk := v.Kind()
if rk == reflect.Ptr {
v = v.Elem()
rk = v.Kind()
}
if rk != reflect.Struct {
panic(fmt.Errorf("Schema value of Struct is expected, but got %s: %#v", reflectKind(rk), v))
}
fields := listAllFields(v)
for _, field := range fields {
typeField := field.sf
fieldName := typeField.Tag.Get("tfsdk")
if fieldName == "-" {
continue
}
// TODO: handle optional and all kinds of stuff

}

}
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 @@ -12,7 +12,7 @@ import (
)

type DummyTfSdk struct {
Enabled types.Bool `tfsdk:"enabled"`
Enabled types.Bool `tfsdk:"enabled",tf:"optional"`
Workers types.Int64 `tfsdk:"workers"`
Floats types.Float64 `tfsdk:"floats"`
Description types.String `tfsdk:"description"`
Expand Down

0 comments on commit d72ed85

Please sign in to comment.