@@ -10,8 +10,12 @@ import (
10
10
"net/http"
11
11
"net/url"
12
12
"regexp"
13
+ "strconv"
13
14
"strings"
14
15
16
+ "github.com/hashicorp/terraform-plugin-framework/attr"
17
+ "github.com/hashicorp/terraform-plugin-framework/types"
18
+ "github.com/hashicorp/terraform-plugin-framework/types/basetypes"
15
19
constants "github.com/microsoft/terraform-provider-power-platform/constants"
16
20
api "github.com/microsoft/terraform-provider-power-platform/internal/powerplatform/api"
17
21
)
@@ -96,7 +100,7 @@ func (client *DataRecordClient) getEnvironment(ctx context.Context, environmentI
96
100
return & env , nil
97
101
}
98
102
99
- func (client * DataRecordClient ) GetDataRecord (ctx context.Context , recordId string , environmentId string , tableName string ) (* map [ string ] interface {} , error ) {
103
+ func (client * DataRecordClient ) GetDataRecord (ctx context.Context , recordId string , environmentId string , tableName string , columns types. Dynamic ) (* basetypes. DynamicValue , error ) {
100
104
environmentUrl , err := client .GetEnvironmentUrlById (ctx , environmentId )
101
105
if err != nil {
102
106
return nil , err
@@ -118,7 +122,46 @@ func (client *DataRecordClient) GetDataRecord(ctx context.Context, recordId stri
118
122
return nil , err
119
123
}
120
124
121
- return & result , nil
125
+ var mapColumns map [string ]interface {}
126
+ jsonColumns , _ := json .Marshal (columns .String ())
127
+ unquotedJsonColumns , _ := strconv .Unquote (string (jsonColumns ))
128
+ json .Unmarshal ([]byte (unquotedJsonColumns ), & mapColumns )
129
+
130
+ attributeTypes := make (map [string ]attr.Type )
131
+ attributes := make (map [string ]attr.Value )
132
+
133
+ for key , value := range mapColumns {
134
+ switch value .(type ) {
135
+ case bool :
136
+ v , ok := result [key ].(bool )
137
+ if ok {
138
+ attributeTypes [key ] = types .BoolType
139
+ attributes [key ] = types .BoolValue (v )
140
+ }
141
+ case int64 :
142
+ v , ok := result [key ].(int64 )
143
+ if ok {
144
+ attributeTypes [key ] = types .Int64Type
145
+ attributes [key ] = types .Int64Value (v )
146
+ }
147
+ case float64 :
148
+ v , ok := result [key ].(float64 )
149
+ if ok {
150
+ attributeTypes [key ] = types .Float64Type
151
+ attributes [key ] = types .Float64Value (v )
152
+ }
153
+ case string :
154
+ v , ok := result [key ].(string )
155
+ if ok {
156
+ attributeTypes [key ] = types .StringType
157
+ attributes [key ] = types .StringValue (v )
158
+ }
159
+ }
160
+ }
161
+ stateValue , _ := types .ObjectValue (attributeTypes , attributes )
162
+ newState := basetypes .NewDynamicValue (stateValue )
163
+
164
+ return & newState , nil
122
165
}
123
166
124
167
func (client * DataRecordClient ) ApplyDataRecord (ctx context.Context , recordId string , environmentId string , tableName string , columns map [string ]interface {}) (* DataRecordDto , error ) {
0 commit comments