Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tfsdk: Switch Config, Plan, and State type Schema fields to interface #544

Merged
merged 2 commits into from Nov 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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