Skip to content

Commit

Permalink
tfprotov5+tfprotov6: Include private state in MoveResourceState (#372)
Browse files Browse the repository at this point in the history
Reference: hashicorp/terraform#34575

To match upstream changes. No changelog is necessary as this is unreleased.
  • Loading branch information
bflad committed Jan 26, 2024
1 parent c9a4f80 commit 5206b46
Show file tree
Hide file tree
Showing 14 changed files with 481 additions and 371 deletions.
1 change: 1 addition & 0 deletions tfprotov5/internal/fromproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func MoveResourceStateRequest(in *tfplugin5.MoveResourceState_Request) *tfprotov
}

resp := &tfprotov5.MoveResourceStateRequest{
SourcePrivate: in.SourcePrivate,
SourceProviderAddress: in.SourceProviderAddress,
SourceSchemaVersion: in.SourceSchemaVersion,
SourceState: RawState(in.SourceState),
Expand Down
8 changes: 8 additions & 0 deletions tfprotov5/internal/fromproto/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func TestMoveResourceStateRequest(t *testing.T) {
in: &tfplugin5.MoveResourceState_Request{},
expected: &tfprotov5.MoveResourceStateRequest{},
},
"SourcePrivate": {
in: &tfplugin5.MoveResourceState_Request{
SourcePrivate: []byte(`{}`),
},
expected: &tfprotov5.MoveResourceStateRequest{
SourcePrivate: []byte(`{}`),
},
},
"SourceProviderAddress": {
in: &tfplugin5.MoveResourceState_Request{
SourceProviderAddress: "test",
Expand Down
447 changes: 235 additions & 212 deletions tfprotov5/internal/tfplugin5/tfplugin5.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tfprotov5/internal/tfplugin5/tfplugin5.proto
Original file line number Diff line number Diff line change
Expand Up @@ -490,13 +490,20 @@ message MoveResourceState {

// The resource type that the resource is being moved to.
string target_type_name = 5;

// The private state of the resource being moved.
bytes source_private = 6;
}

message Response {
// The state of the resource after it has been moved.
DynamicValue target_state = 1;

// Any diagnostics that occurred during the move.
repeated Diagnostic diagnostics = 2;

// The private state of the resource after it has been moved.
bytes target_private = 3;
}
}

Expand Down
5 changes: 3 additions & 2 deletions tfprotov5/internal/toproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ func MoveResourceState_Response(in *tfprotov5.MoveResourceStateResponse) *tfplug
}

resp := &tfplugin5.MoveResourceState_Response{
Diagnostics: Diagnostics(in.Diagnostics),
TargetState: DynamicValue(in.TargetState),
Diagnostics: Diagnostics(in.Diagnostics),
TargetPrivate: in.TargetPrivate,
TargetState: DynamicValue(in.TargetState),
}

return resp
Expand Down
9 changes: 9 additions & 0 deletions tfprotov5/internal/toproto/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ func TestMoveResourceState_Response(t *testing.T) {
},
},
},
"TargetPrivate": {
in: &tfprotov5.MoveResourceStateResponse{
TargetPrivate: []byte(`{}`),
},
expected: &tfplugin5.MoveResourceState_Response{
Diagnostics: []*tfplugin5.Diagnostic{},
TargetPrivate: []byte(`{}`),
},
},
"TargetState": {
in: &tfprotov5.MoveResourceStateResponse{
TargetState: testTfprotov5DynamicValue(),
Expand Down
6 changes: 6 additions & 0 deletions tfprotov5/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,9 @@ type ImportedResource struct {
// must have enabled the MoveResourceState server capability to enable these
// requests.
type MoveResourceStateRequest struct {
// SourcePrivate is the private state of the source resource.
SourcePrivate []byte

// SourceProviderAddress is the address of the provider for the source
// resource type.
SourceProviderAddress string
Expand All @@ -532,6 +535,9 @@ type MoveResourceStateRequest struct {
// MoveResourceStateResponse is the response from the provider containing
// the moved state for the given resource.
type MoveResourceStateResponse struct {
// TargetPrivate is the target resource private state after the move.
TargetPrivate []byte

// TargetState is the target resource state after the move.
TargetState *DynamicValue

Expand Down
1 change: 1 addition & 0 deletions tfprotov6/internal/fromproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ func MoveResourceStateRequest(in *tfplugin6.MoveResourceState_Request) *tfprotov
}

resp := &tfprotov6.MoveResourceStateRequest{
SourcePrivate: in.SourcePrivate,
SourceProviderAddress: in.SourceProviderAddress,
SourceSchemaVersion: in.SourceSchemaVersion,
SourceState: RawState(in.SourceState),
Expand Down
8 changes: 8 additions & 0 deletions tfprotov6/internal/fromproto/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,14 @@ func TestMoveResourceStateRequest(t *testing.T) {
in: &tfplugin6.MoveResourceState_Request{},
expected: &tfprotov6.MoveResourceStateRequest{},
},
"SourcePrivate": {
in: &tfplugin6.MoveResourceState_Request{
SourcePrivate: []byte(`{}`),
},
expected: &tfprotov6.MoveResourceStateRequest{
SourcePrivate: []byte(`{}`),
},
},
"SourceProviderAddress": {
in: &tfplugin6.MoveResourceState_Request{
SourceProviderAddress: "test",
Expand Down
333 changes: 178 additions & 155 deletions tfprotov6/internal/tfplugin6/tfplugin6.pb.go

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions tfprotov6/internal/tfplugin6/tfplugin6.proto
Original file line number Diff line number Diff line change
Expand Up @@ -507,13 +507,20 @@ message MoveResourceState {

// The resource type that the resource is being moved to.
string target_type_name = 5;

// The private state of the resource being moved.
bytes source_private = 6;
}

message Response {
// The state of the resource after it has been moved.
DynamicValue target_state = 1;

// Any diagnostics that occurred during the move.
repeated Diagnostic diagnostics = 2;

// The private state of the resource after it has been moved.
bytes target_private = 3;
}
}

Expand Down
5 changes: 3 additions & 2 deletions tfprotov6/internal/toproto/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,9 @@ func MoveResourceState_Response(in *tfprotov6.MoveResourceStateResponse) *tfplug
}

resp := &tfplugin6.MoveResourceState_Response{
Diagnostics: Diagnostics(in.Diagnostics),
TargetState: DynamicValue(in.TargetState),
Diagnostics: Diagnostics(in.Diagnostics),
TargetPrivate: in.TargetPrivate,
TargetState: DynamicValue(in.TargetState),
}

return resp
Expand Down
9 changes: 9 additions & 0 deletions tfprotov6/internal/toproto/resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -386,6 +386,15 @@ func TestMoveResourceState_Response(t *testing.T) {
},
},
},
"TargetPrivate": {
in: &tfprotov6.MoveResourceStateResponse{
TargetPrivate: []byte(`{}`),
},
expected: &tfplugin6.MoveResourceState_Response{
Diagnostics: []*tfplugin6.Diagnostic{},
TargetPrivate: []byte(`{}`),
},
},
"TargetState": {
in: &tfprotov6.MoveResourceStateResponse{
TargetState: testTfprotov6DynamicValue(),
Expand Down
6 changes: 6 additions & 0 deletions tfprotov6/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,9 @@ type ImportedResource struct {
// must have enabled the MoveResourceState server capability to enable these
// requests.
type MoveResourceStateRequest struct {
// SourcePrivate is the private state of the source resource.
SourcePrivate []byte

// SourceProviderAddress is the address of the provider for the source
// resource type.
SourceProviderAddress string
Expand All @@ -529,6 +532,9 @@ type MoveResourceStateRequest struct {
// MoveResourceStateResponse is the response from the provider containing
// the moved state for the given resource.
type MoveResourceStateResponse struct {
// TargetPrivate is the target resource private state after the move.
TargetPrivate []byte

// TargetState is the target resource state after the move.
TargetState *DynamicValue

Expand Down

0 comments on commit 5206b46

Please sign in to comment.