forked from hashicorp/terraform-plugin-framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvalue_from.go
23 lines (19 loc) · 769 Bytes
/
value_from.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package tfsdk
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/reflect"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
// ValueFrom takes the Go value `val` and populates `target` with an attr.Value,
// based on the type definition provided in `targetType`.
//
// This is achieved using reflection rules provided by the internal/reflect package.
func ValueFrom(ctx context.Context, val interface{}, targetType attr.Type, target interface{}) diag.Diagnostics {
v, diags := reflect.FromValue(ctx, targetType, val, tftypes.NewAttributePath())
if diags.HasError() {
return diags
}
return ValueAs(ctx, v, target)
}