Skip to content

Commit 038d486

Browse files
committed
Move toproto5/6 Deferred conversion handling to its own files
1 parent 5ab0c24 commit 038d486

File tree

6 files changed

+62
-24
lines changed

6 files changed

+62
-24
lines changed

internal/toproto5/deferred.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package toproto5
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
)
12+
13+
func DataSourceDeferred(fw *datasource.Deferred) *tfprotov5.Deferred {
14+
if fw == nil {
15+
return nil
16+
}
17+
return &tfprotov5.Deferred{
18+
Reason: tfprotov5.DeferredReason(fw.Reason),
19+
}
20+
}
21+
22+
func ResourceDeferred(fw *resource.Deferred) *tfprotov5.Deferred {
23+
if fw == nil {
24+
return nil
25+
}
26+
return &tfprotov5.Deferred{
27+
Reason: tfprotov5.DeferredReason(fw.Reason),
28+
}
29+
}

internal/toproto5/importresourcestate.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func ImportResourceStateResponse(ctx context.Context, fw *fwserver.ImportResourc
1919
}
2020

2121
proto5 := &tfprotov5.ImportResourceStateResponse{
22+
Deferred: ResourceDeferred(fw.Deferred),
2223
Diagnostics: Diagnostics(ctx, fw.Diagnostics),
2324
}
2425

@@ -34,11 +35,5 @@ func ImportResourceStateResponse(ctx context.Context, fw *fwserver.ImportResourc
3435
proto5.ImportedResources = append(proto5.ImportedResources, proto5ImportedResource)
3536
}
3637

37-
if fw.Deferred != nil {
38-
proto5.Deferred = &tfprotov5.Deferred{
39-
Reason: tfprotov5.DeferredReason(fw.Deferred.Reason),
40-
}
41-
}
42-
4338
return proto5
4439
}

internal/toproto5/planresourcechange.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ func PlanResourceChangeResponse(ctx context.Context, fw *fwserver.PlanResourceCh
2020
}
2121

2222
proto5 := &tfprotov5.PlanResourceChangeResponse{
23+
Deferred: ResourceDeferred(fw.Deferred),
2324
Diagnostics: Diagnostics(ctx, fw.Diagnostics),
2425
}
2526

@@ -38,11 +39,5 @@ func PlanResourceChangeResponse(ctx context.Context, fw *fwserver.PlanResourceCh
3839
proto5.Diagnostics = append(proto5.Diagnostics, Diagnostics(ctx, diags)...)
3940
proto5.PlannedPrivate = plannedPrivate
4041

41-
if fw.Deferred != nil {
42-
proto5.Deferred = &tfprotov5.Deferred{
43-
Reason: tfprotov5.DeferredReason(fw.Deferred.Reason),
44-
}
45-
}
46-
4742
return proto5
4843
}

internal/toproto5/readdatasource.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func ReadDataSourceResponse(ctx context.Context, fw *fwserver.ReadDataSourceResp
1919
}
2020

2121
proto5 := &tfprotov5.ReadDataSourceResponse{
22+
Deferred: DataSourceDeferred(fw.Deferred),
2223
Diagnostics: Diagnostics(ctx, fw.Diagnostics),
2324
}
2425

@@ -27,11 +28,5 @@ func ReadDataSourceResponse(ctx context.Context, fw *fwserver.ReadDataSourceResp
2728
proto5.Diagnostics = append(proto5.Diagnostics, Diagnostics(ctx, diags)...)
2829
proto5.State = state
2930

30-
if fw.Deferred != nil {
31-
proto5.Deferred = &tfprotov5.Deferred{
32-
Reason: tfprotov5.DeferredReason(fw.Deferred.Reason),
33-
}
34-
}
35-
3631
return proto5
3732
}

internal/toproto5/readresource.go

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func ReadResourceResponse(ctx context.Context, fw *fwserver.ReadResourceResponse
1919
}
2020

2121
proto5 := &tfprotov5.ReadResourceResponse{
22+
Deferred: ResourceDeferred(fw.Deferred),
2223
Diagnostics: Diagnostics(ctx, fw.Diagnostics),
2324
}
2425

@@ -32,11 +33,5 @@ func ReadResourceResponse(ctx context.Context, fw *fwserver.ReadResourceResponse
3233
proto5.Diagnostics = append(proto5.Diagnostics, Diagnostics(ctx, diags)...)
3334
proto5.Private = newPrivate
3435

35-
if fw.Deferred != nil {
36-
proto5.Deferred = &tfprotov5.Deferred{
37-
Reason: tfprotov5.DeferredReason(fw.Deferred.Reason),
38-
}
39-
}
40-
4136
return proto5
4237
}

internal/toproto6/deferred.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package toproto6
5+
6+
import (
7+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
8+
9+
"github.com/hashicorp/terraform-plugin-framework/datasource"
10+
"github.com/hashicorp/terraform-plugin-framework/resource"
11+
)
12+
13+
func DataSourceDeferred(fw *datasource.Deferred) *tfprotov6.Deferred {
14+
if fw == nil {
15+
return nil
16+
}
17+
return &tfprotov6.Deferred{
18+
Reason: tfprotov6.DeferredReason(fw.Reason),
19+
}
20+
}
21+
22+
func ResourceDeferred(fw *resource.Deferred) *tfprotov6.Deferred {
23+
if fw == nil {
24+
return nil
25+
}
26+
return &tfprotov6.Deferred{
27+
Reason: tfprotov6.DeferredReason(fw.Reason),
28+
}
29+
}

0 commit comments

Comments
 (0)