Skip to content

Commit

Permalink
tfsdk: Switch Config, Plan, and State type Schema fields to interface (
Browse files Browse the repository at this point in the history
…#544)

Reference: #132

As part of upcoming effort to split schema functionality into the datasource, provider, and resource packages, there are some internal implementation details which need to be sorted beforehand. Throughout the 0.x versions, schema functionality has been migrated from the `tfsdk` package into the `internal/fwschema` package, however the exported `Config`, `Plan`, and `State` type `Schema` fields remained hardcoded to the `tfsdk.Schema` type. This change migrates the field type to the `fwschema.Schema` interface, so other framework schema implementations can be introduced.
  • Loading branch information
bflad committed Nov 17, 2022
1 parent 59a847d commit baf4cfd
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 43 deletions.
3 changes: 3 additions & 0 deletions .changelog/544.txt
@@ -0,0 +1,3 @@
```release-note:breaking-change
tfsdk: The `Config`, `Plan`, and `State` type `Schema` field type has been updated from `tfsdk.Schema` to the generic `fwschema.Schema` interface to enable additional schema implementations
```
23 changes: 0 additions & 23 deletions internal/fwserver/schema.go

This file was deleted.

6 changes: 3 additions & 3 deletions internal/fwserver/server_createresource.go
Expand Up @@ -62,11 +62,11 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest,

createReq := resource.CreateRequest{
Config: tfsdk.Config{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
Plan: tfsdk.Plan{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
}
Expand All @@ -75,7 +75,7 @@ func (s *Server) CreateResource(ctx context.Context, req *CreateResourceRequest,

createResp := resource.CreateResponse{
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
Private: privateProviderData,
Expand Down
4 changes: 2 additions & 2 deletions internal/fwserver/server_deleteresource.go
Expand Up @@ -59,13 +59,13 @@ func (s *Server) DeleteResource(ctx context.Context, req *DeleteResourceRequest,

deleteReq := resource.DeleteRequest{
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: tftypes.NewValue(req.ResourceSchema.Type().TerraformType(ctx), nil),
},
}
deleteResp := resource.DeleteResponse{
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: tftypes.NewValue(req.ResourceSchema.Type().TerraformType(ctx), nil),
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/fwserver/server_planresourcechange.go
Expand Up @@ -70,21 +70,21 @@ func (s *Server) PlanResourceChange(ctx context.Context, req *PlanResourceChange
if req.Config == nil {
req.Config = &tfsdk.Config{
Raw: nullTfValue,
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
}
}

if req.ProposedNewState == nil {
req.ProposedNewState = &tfsdk.Plan{
Raw: nullTfValue,
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
}
}

if req.PriorState == nil {
req.PriorState = &tfsdk.State{
Raw: nullTfValue,
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
}
}

Expand Down
4 changes: 2 additions & 2 deletions internal/fwserver/server_readdatasource.go
Expand Up @@ -53,12 +53,12 @@ func (s *Server) ReadDataSource(ctx context.Context, req *ReadDataSourceRequest,

readReq := datasource.ReadRequest{
Config: tfsdk.Config{
Schema: schema(req.DataSourceSchema),
Schema: req.DataSourceSchema,
},
}
readResp := datasource.ReadResponse{
State: tfsdk.State{
Schema: schema(req.DataSourceSchema),
Schema: req.DataSourceSchema,
},
}

Expand Down
8 changes: 4 additions & 4 deletions internal/fwserver/server_updateresource.go
Expand Up @@ -63,21 +63,21 @@ func (s *Server) UpdateResource(ctx context.Context, req *UpdateResourceRequest,

updateReq := resource.UpdateRequest{
Config: tfsdk.Config{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
Plan: tfsdk.Plan{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
}
updateResp := resource.UpdateResponse{
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: nullSchemaData,
},
}
Expand Down
6 changes: 3 additions & 3 deletions internal/fwserver/server_upgraderesourcestate.go
Expand Up @@ -92,7 +92,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS
}

resp.UpgradedState = &tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: rawStateValue,
}

Expand Down Expand Up @@ -181,7 +181,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS

upgradeResourceStateResponse := resource.UpgradeStateResponse{
State: tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
// Raw is intentionally not set.
},
}
Expand Down Expand Up @@ -216,7 +216,7 @@ func (s *Server) UpgradeResourceState(ctx context.Context, req *UpgradeResourceS
}

resp.UpgradedState = &tfsdk.State{
Schema: schema(req.ResourceSchema),
Schema: req.ResourceSchema,
Raw: upgradedStateValue,
}

Expand Down
3 changes: 2 additions & 1 deletion tfsdk/config.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
Expand All @@ -12,7 +13,7 @@ import (
// Config represents a Terraform config.
type Config struct {
Raw tftypes.Value
Schema Schema
Schema fwschema.Schema
}

// Get populates the struct passed as `target` with the entire config.
Expand Down
3 changes: 2 additions & 1 deletion tfsdk/plan.go
Expand Up @@ -4,6 +4,7 @@ import (
"context"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
Expand All @@ -12,7 +13,7 @@ import (
// Plan represents a Terraform plan.
type Plan struct {
Raw tftypes.Value
Schema Schema
Schema fwschema.Schema
}

// Get populates the struct passed as `target` with the entire plan.
Expand Down
3 changes: 2 additions & 1 deletion tfsdk/state.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschemadata"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-go/tftypes"
Expand All @@ -13,7 +14,7 @@ import (
// State represents a Terraform state.
type State struct {
Raw tftypes.Value
Schema Schema
Schema fwschema.Schema
}

// Get populates the struct passed as `target` with the entire state.
Expand Down

0 comments on commit baf4cfd

Please sign in to comment.