You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
types: Introduce ListValueFrom, MapValueFrom, ObjectValueFrom, and SetValueFrom functions (#522)
Reference: #520
These will enable provider developers to use the framework type system's built-in conversion rules to create collection types, rather than using more generic `tfsdk.ValueFrom()` or other methodologies.
In this example, a map using standard Go types is used to create a `types.Map` framework type with known values:
```go
apiMap := map[string]string{
"key1": "value1",
"key2": "value2",
}
fwMap, diags := types.MapValueFrom(ctx, types.StringType, apiMap)
```
There may be additional use cases or needs that get teased out with this introduction, such as the ability to create a `types.Object` from a `map[string]any`, however those can be handled in potential future feature requests.
types: Added `ListValueFrom()`, `MapValueFrom()`, `ObjectValueFrom()`, and `SetValueFrom()` functions, which can create value types from standard Go types using reflection similar to `tfsdk.ValueFrom()`
"An unexpected error was encountered trying to validate an attribute value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+
417
+
"expected List value, received tftypes.Value with value: tftypes.String<\"oops\">",
418
+
),
419
+
},
420
+
},
421
+
"invalid-type": {
422
+
elementType: StringType,
423
+
elements: []bool{true},
424
+
expected: ListUnknown(StringType),
425
+
expectedDiags: diag.Diagnostics{
426
+
diag.NewAttributeErrorDiagnostic(
427
+
path.Empty().AtListIndex(0),
428
+
"Value Conversion Error",
429
+
"An unexpected error was encountered trying to convert the Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+
430
+
"can't unmarshal tftypes.Bool into *string, expected string",
"An unexpected error was encountered trying to validate an attribute value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+
396
+
"expected Map value, received tftypes.Value with value: tftypes.String<\"oops\">",
397
+
),
398
+
},
399
+
},
400
+
"invalid-type": {
401
+
elementType: StringType,
402
+
elements: map[string]bool{"key1": true},
403
+
expected: MapUnknown(StringType),
404
+
expectedDiags: diag.Diagnostics{
405
+
diag.NewAttributeErrorDiagnostic(
406
+
path.Empty().AtMapKey("key1"),
407
+
"Value Conversion Error",
408
+
"An unexpected error was encountered trying to convert the Terraform value. This is always an error in the provider. Please report the following to the provider developer:\n\n"+
409
+
"can't unmarshal tftypes.Bool into *string, expected string",
0 commit comments