Skip to content

Commit

Permalink
Prevent missing method MoveResourceState (#223)
Browse files Browse the repository at this point in the history
Reference: hashicorp/terraform-plugin-go#388

These changes are so the testing provider is compliant with the upcoming `tfprotov5` and `tfprotov6` packages which require provider implementations to fully implement function server handling (already covered) and MoveResourceState (needs covering, hence this change). Almost the entire ecosystem will not have this issue as the higher level SDKs (terraform-plugin-framework, terraform-plugin-sdk, etc.) handle these protocol operations manually, but this test provider is written directly in the low level SDK, so it must implement the necessary changes itself prior to that upstream breaking change.
  • Loading branch information
bflad authored Mar 12, 2024
1 parent eac47aa commit b7a6f3a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/protocolprovider/resource_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,21 @@ func (r resourceRouter) ImportResourceState(ctx context.Context, req *tfprotov5.
}
return res.ImportResourceState(ctx, req)
}

func (r resourceRouter) MoveResourceState(ctx context.Context, req *tfprotov5.MoveResourceStateRequest) (*tfprotov5.MoveResourceStateResponse, error) {
_, ok := r[req.TargetTypeName]
if !ok {
return nil, errUnsupportedResource(req.TargetTypeName)
}
// If this support ever needs to be added, this can follow the existing
// pattern of calling res.MoveResourceState(ctx, req).
return &tfprotov5.MoveResourceStateResponse{
Diagnostics: []*tfprotov5.Diagnostic{
{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "Unsupported Resource Operation",
Detail: "MoveResourceState is not supported by this provider.",
},
},
}, nil
}
18 changes: 18 additions & 0 deletions internal/protocolv6provider/resource_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,21 @@ func (r resourceRouter) ImportResourceState(ctx context.Context, req *tfprotov6.
}
return res.ImportResourceState(ctx, req)
}

func (r resourceRouter) MoveResourceState(ctx context.Context, req *tfprotov6.MoveResourceStateRequest) (*tfprotov6.MoveResourceStateResponse, error) {
_, ok := r[req.TargetTypeName]
if !ok {
return nil, errUnsupportedResource(req.TargetTypeName)
}
// If this support ever needs to be added, this can follow the existing
// pattern of calling res.MoveResourceState(ctx, req).
return &tfprotov6.MoveResourceStateResponse{
Diagnostics: []*tfprotov6.Diagnostic{
{
Severity: tfprotov6.DiagnosticSeverityError,
Summary: "Unsupported Resource Operation",
Detail: "MoveResourceState is not supported by this provider.",
},
},
}, nil
}

0 comments on commit b7a6f3a

Please sign in to comment.