Skip to content

Commit

Permalink
tfprotov5+tfprotov6: Initial MoveResourceState support (#364)
Browse files Browse the repository at this point in the history
Reference: #362
Reference: #363

The next version of the plugin protocol (5.5/6.5) includes support for moving resource state. This change introduces the initial implementation of that support including:

- Updated Protocol Buffers definitions
- Re-generated Protocol Buffers Go code
- Initial implementations of `tfprotov5` and `tfprotov6` package abstractions and wiring between those abstractions and the Protocol Buffers generated Go code
- Initial implementations of `tfprotov5/tf5server` and `tfprotov6/tf6server` for the new `MoveResourceState` RPC

This temporarily will not require `ProviderServer` implementations to include `MoveResourceState` implementation, however that change will occur in a subsequent release.
  • Loading branch information
bflad authored Jan 17, 2024
1 parent 7553bff commit bd50706
Show file tree
Hide file tree
Showing 24 changed files with 2,577 additions and 1,553 deletions.
6 changes: 6 additions & 0 deletions .changes/unreleased/FEATURES-20240112-153355.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: FEATURES
body: 'tfprotov5+tfprotov6: Upgraded protocols and added types to support the `MoveResourceState`
RPC'
time: 2024-01-12T15:33:55.940212-08:00
custom:
Issue: "364"
6 changes: 6 additions & 0 deletions .changes/unreleased/NOTES-20240112-153501.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
kind: NOTES
body: 'tfprotov5+tfprotov6: An upcoming release will require the MoveResourceState
implementation as part of ResourceServer'
time: 2024-01-12T15:35:01.843365-08:00
custom:
Issue: "364"
17 changes: 14 additions & 3 deletions tfprotov5/internal/fromproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ func ValidateResourceTypeConfigResponse(in *tfplugin5.ValidateResourceTypeConfig

func UpgradeResourceStateRequest(in *tfplugin5.UpgradeResourceState_Request) (*tfprotov5.UpgradeResourceStateRequest, error) {
resp := &tfprotov5.UpgradeResourceStateRequest{
RawState: RawState(in.RawState),
TypeName: in.TypeName,
Version: in.Version,
}
if in.RawState != nil {
resp.RawState = RawState(in.RawState)
}

return resp, nil
}

Expand Down Expand Up @@ -219,3 +218,15 @@ func ImportedResources(in []*tfplugin5.ImportResourceState_ImportedResource) ([]
}
return resp, nil
}

func MoveResourceStateRequest(in *tfplugin5.MoveResourceState_Request) (*tfprotov5.MoveResourceStateRequest, error) {
resp := &tfprotov5.MoveResourceStateRequest{
SourceProviderAddress: in.SourceProviderAddress,
SourceSchemaVersion: in.SourceSchemaVersion,
SourceState: RawState(in.SourceState),
SourceTypeName: in.SourceTypeName,
TargetTypeName: in.TargetTypeName,
}

return resp, nil
}
1 change: 1 addition & 0 deletions tfprotov5/internal/fromproto/server_capabilities.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func ServerCapabilities(in *tfplugin5.ServerCapabilities) *tfprotov5.ServerCapab

return &tfprotov5.ServerCapabilities{
GetProviderSchemaOptional: in.GetProviderSchemaOptional,
MoveResourceState: in.MoveResourceState,
PlanDestroy: in.PlanDestroy,
}
}
4 changes: 4 additions & 0 deletions tfprotov5/internal/fromproto/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ import (
)

func RawState(in *tfplugin5.RawState) *tfprotov5.RawState {
if in == nil {
return nil
}

return &tfprotov5.RawState{
JSON: in.Json,
Flatmap: in.Flatmap,
Expand Down
Loading

0 comments on commit bd50706

Please sign in to comment.