Skip to content

Commit 0ba16ff

Browse files
authored
tfsdk: Additional preparations for multiple schema implementations (#440)
Reference: #365 This is a followup to the initial schema logic migration that tries to further prepare the Go module for multiple schema implementations. - Removes unexported schema-based functions/methods from the `tfsdk` package (`pathMatches` will be handled as part of schema data internalization) - Removes `tftypes.Type` handling from schemas as `(attr.Type).TerraformType()` already does this - Tries to standardize on `Type()` for fetching framework type (`attr.Type`) information from schema types (`Attribute` will get fixed once `tfsdk.Attribute` is removed) - Tries to standardize `Schema` method signatures for framework types/diagnostics and terraform-plugin-go types/errors - Prepares `NestedAttributes` implementations for unit testing across multiple attribute implementations
1 parent e6bc60e commit 0ba16ff

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2057
-491
lines changed

.changelog/440.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:note
2+
tfsdk: The `Schema` type `AttributeAtPath()` method signature will be updated from a `*tftypes.AttributePath` parameter to `path.Path` in the next release. Switch to the `AttributeAtTerraformPath()` method if `*tftypes.AttributePath` handling is still necessary.
3+
```
4+
5+
```release-note:note
6+
tfsdk: The `Schema` type `AttributeTypeAtPath()` method has been deprecated for the `TypeAtPath()` and `TypeAtTerraformPath()` methods.
7+
```
8+
9+
```release-note:note
10+
tfsdk: The `Schema` type `AttributeType()` method has been deprecated in preference of the `Type()` method.
11+
```
12+
13+
```release-note:note
14+
tfsdk: The `Schema` type `TerraformType()` method has been deprecated in preference of calling `Type().TerraformType()`.
15+
```

internal/fromproto5/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Config(ctx context.Context, proto5DynamicValue *tfprotov5.DynamicValue, sch
3232
return nil, diags
3333
}
3434

35-
proto5Value, err := proto5DynamicValue.Unmarshal(schema.TerraformType(ctx))
35+
proto5Value, err := proto5DynamicValue.Unmarshal(schema.Type().TerraformType(ctx))
3636

3737
if err != nil {
3838
diags.AddError(

internal/fromproto5/importresourcestate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ImportResourceStateRequest(ctx context.Context, proto5 *tfprotov5.ImportRes
3737

3838
fw := &fwserver.ImportResourceStateRequest{
3939
EmptyState: tfsdk.State{
40-
Raw: tftypes.NewValue(resourceSchema.TerraformType(ctx), nil),
40+
Raw: tftypes.NewValue(resourceSchema.Type().TerraformType(ctx), nil),
4141
Schema: tfsdkSchema(resourceSchema),
4242
},
4343
ID: proto5.ID,

internal/fromproto5/importresourcestate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestImportResourceStateRequest(t *testing.T) {
2929
}
3030

3131
testFwEmptyState := tfsdk.State{
32-
Raw: tftypes.NewValue(testFwSchema.TerraformType(context.Background()), nil),
32+
Raw: tftypes.NewValue(testFwSchema.Type().TerraformType(context.Background()), nil),
3333
Schema: *testFwSchema,
3434
}
3535

internal/fromproto5/plan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Plan(ctx context.Context, proto5DynamicValue *tfprotov5.DynamicValue, schem
3232
return nil, diags
3333
}
3434

35-
proto5Value, err := proto5DynamicValue.Unmarshal(schema.TerraformType(ctx))
35+
proto5Value, err := proto5DynamicValue.Unmarshal(schema.Type().TerraformType(ctx))
3636

3737
if err != nil {
3838
diags.AddError(

internal/fromproto5/providermeta.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,15 +24,15 @@ func ProviderMeta(ctx context.Context, proto5DynamicValue *tfprotov5.DynamicValu
2424
var diags diag.Diagnostics
2525

2626
fw := &tfsdk.Config{
27-
Raw: tftypes.NewValue(schema.TerraformType(ctx), nil),
27+
Raw: tftypes.NewValue(schema.Type().TerraformType(ctx), nil),
2828
Schema: tfsdkSchema(schema),
2929
}
3030

3131
if proto5DynamicValue == nil {
3232
return fw, nil
3333
}
3434

35-
proto5Value, err := proto5DynamicValue.Unmarshal(schema.TerraformType(ctx))
35+
proto5Value, err := proto5DynamicValue.Unmarshal(schema.Type().TerraformType(ctx))
3636

3737
if err != nil {
3838
diags.AddError(

internal/fromproto5/state.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func State(ctx context.Context, proto5DynamicValue *tfprotov5.DynamicValue, sche
3232
return nil, diags
3333
}
3434

35-
proto5Value, err := proto5DynamicValue.Unmarshal(schema.TerraformType(ctx))
35+
proto5Value, err := proto5DynamicValue.Unmarshal(schema.Type().TerraformType(ctx))
3636

3737
if err != nil {
3838
diags.AddError(

internal/fromproto6/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func Config(ctx context.Context, proto6DynamicValue *tfprotov6.DynamicValue, sch
3232
return nil, diags
3333
}
3434

35-
proto6Value, err := proto6DynamicValue.Unmarshal(schema.TerraformType(ctx))
35+
proto6Value, err := proto6DynamicValue.Unmarshal(schema.Type().TerraformType(ctx))
3636

3737
if err != nil {
3838
diags.AddError(

internal/fromproto6/importresourcestate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func ImportResourceStateRequest(ctx context.Context, proto6 *tfprotov6.ImportRes
3737

3838
fw := &fwserver.ImportResourceStateRequest{
3939
EmptyState: tfsdk.State{
40-
Raw: tftypes.NewValue(resourceSchema.TerraformType(ctx), nil),
40+
Raw: tftypes.NewValue(resourceSchema.Type().TerraformType(ctx), nil),
4141
Schema: tfsdkSchema(resourceSchema),
4242
},
4343
ID: proto6.ID,

internal/fromproto6/importresourcestate_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ func TestImportResourceStateRequest(t *testing.T) {
2929
}
3030

3131
testFwEmptyState := tfsdk.State{
32-
Raw: tftypes.NewValue(testFwSchema.TerraformType(context.Background()), nil),
32+
Raw: tftypes.NewValue(testFwSchema.Type().TerraformType(context.Background()), nil),
3333
Schema: *testFwSchema,
3434
}
3535

0 commit comments

Comments
 (0)