Skip to content

Commit 6785738

Browse files
committed
Add initial updates for identity to MoveResourceState RPC
1 parent 8ab70d0 commit 6785738

File tree

3 files changed

+39
-9
lines changed

3 files changed

+39
-9
lines changed

internal/fromproto5/moveresourcestate.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ func MoveResourceStateRequest(ctx context.Context, proto5 *tfprotov5.MoveResourc
4545
TargetResource: resource,
4646
TargetResourceSchema: resourceSchema,
4747
TargetTypeName: proto5.TargetTypeName,
48+
SourceIdentity: (*tfprotov6.RawState)(proto5.SourceIdentity),
4849
}
4950

5051
sourcePrivate, sourcePrivateDiags := privatestate.NewData(ctx, proto5.SourcePrivate)

internal/fwserver/server_moveresourcestate.go

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -65,14 +65,23 @@ type MoveResourceStateRequest struct {
6565
// TargetTypeName is the type name of the target resource as given by
6666
// Terraform across the protocol.
6767
TargetTypeName string
68+
69+
// SourceIdentity is the identity of the source resource.
70+
//
71+
// Only the underlying JSON field is populated.
72+
SourceIdentity *tfprotov6.RawState
73+
74+
// SourceIdentitySchemaVersion is the version of the source resource state.
75+
SourceIdentitySchemaVersion int64
6876
}
6977

7078
// MoveResourceStateResponse is the framework server response for the
7179
// MoveResourceState RPC.
7280
type MoveResourceStateResponse struct {
73-
Diagnostics diag.Diagnostics
74-
TargetPrivate *privatestate.Data
75-
TargetState *tfsdk.State
81+
Diagnostics diag.Diagnostics
82+
TargetPrivate *privatestate.Data
83+
TargetState *tfsdk.State
84+
TargetIdentity *tfsdk.ResourceIdentity
7685
}
7786

7887
// MoveResourceState implements the framework server MoveResourceState RPC.
@@ -125,18 +134,25 @@ func (s *Server) MoveResourceState(ctx context.Context, req *MoveResourceStateRe
125134

126135
for _, resourceStateMover := range resourceStateMovers {
127136
moveStateReq := resource.MoveStateRequest{
128-
SourcePrivate: sourcePrivate,
129-
SourceProviderAddress: req.SourceProviderAddress,
130-
SourceRawState: req.SourceRawState,
131-
SourceSchemaVersion: req.SourceSchemaVersion,
132-
SourceTypeName: req.SourceTypeName,
137+
SourcePrivate: sourcePrivate,
138+
SourceProviderAddress: req.SourceProviderAddress,
139+
SourceRawState: req.SourceRawState,
140+
SourceSchemaVersion: req.SourceSchemaVersion,
141+
SourceTypeName: req.SourceTypeName,
142+
SourceIdentity: req.SourceIdentity,
143+
SourceIdentitySchemaVersion: req.SourceIdentitySchemaVersion,
133144
}
134145
moveStateResp := resource.MoveStateResponse{
135146
TargetPrivate: privatestate.EmptyProviderData(ctx),
136147
TargetState: tfsdk.State{
137148
Schema: req.TargetResourceSchema,
138149
Raw: tftypes.NewValue(req.TargetResourceSchema.Type().TerraformType(ctx), nil),
139150
},
151+
// TODO: See if we need to change this to identity
152+
TargetIdentity: &tfsdk.ResourceIdentity{
153+
Raw: tftypes.NewValue(req.TargetResourceSchema.Type().TerraformType(ctx), nil),
154+
Schema: req.TargetResourceSchema,
155+
},
140156
}
141157

142158
if resourceStateMover.SourceSchema != nil {
@@ -237,6 +253,8 @@ func (s *Server) MoveResourceState(ctx context.Context, req *MoveResourceStateRe
237253
"Source Provider Address: "+req.SourceProviderAddress+"\n"+
238254
"Source Resource Type: "+req.SourceTypeName+"\n"+
239255
"Source Resource Schema Version: "+strconv.FormatInt(req.SourceSchemaVersion, 10)+"\n"+
240-
"Target Resource Type: "+req.TargetTypeName,
256+
"Target Resource Type: "+req.TargetTypeName, //+"\n"+
257+
// "Source Identity Schema Version: "+strconv.FormatInt(req.SourceSchemaVersion, 10),
258+
241259
)
242260
}

resource/move_state.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,14 @@ type MoveStateRequest struct {
7575
// other request fields, to determine whether the request should be handled
7676
// by this particular implementation.
7777
SourceTypeName string
78+
79+
// SourceIdentity is the identity of the source resource.
80+
//
81+
// Only the underlying JSON field is populated.
82+
SourceIdentity *tfprotov6.RawState
83+
84+
// SourceIdentitySchemaVersion is the version of the source resource state.
85+
SourceIdentitySchemaVersion int64
7886
}
7987

8088
// MoveStateResponse represents a response to a MoveStateRequest.
@@ -107,4 +115,7 @@ type MoveStateResponse struct {
107115
// operation. This field is not pre-populated as it is up to implementations
108116
// whether the source private data is relevant for the target resource.
109117
TargetPrivate *privatestate.ProviderData
118+
119+
// TargetIdentity is the identity of the target resource.
120+
TargetIdentity *tfsdk.ResourceIdentity
110121
}

0 commit comments

Comments
 (0)