diff --git a/.changes/unreleased/ENHANCEMENTS-20240507-180758.yaml b/.changes/unreleased/ENHANCEMENTS-20240507-180758.yaml new file mode 100644 index 0000000..daa2f99 --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20240507-180758.yaml @@ -0,0 +1,5 @@ +kind: ENHANCEMENTS +body: 'tf5to6server: Add deferred action request and response fields to RPC translations' +time: 2024-05-07T18:07:58.792141-04:00 +custom: + Issue: "237" diff --git a/.changes/unreleased/ENHANCEMENTS-20240507-180817.yaml b/.changes/unreleased/ENHANCEMENTS-20240507-180817.yaml new file mode 100644 index 0000000..5438cc3 --- /dev/null +++ b/.changes/unreleased/ENHANCEMENTS-20240507-180817.yaml @@ -0,0 +1,5 @@ +kind: ENHANCEMENTS +body: 'tf6to5server: Add deferred action request and response fields to RPC translations' +time: 2024-05-07T18:08:17.113209-04:00 +custom: + Issue: "237" diff --git a/internal/tfprotov5tov6/tfprotov5tov6.go b/internal/tfprotov5tov6/tfprotov5tov6.go index e6bf0b8..3148b26 100644 --- a/internal/tfprotov5tov6/tfprotov5tov6.go +++ b/internal/tfprotov5tov6/tfprotov5tov6.go @@ -70,11 +70,24 @@ func ConfigureProviderRequest(in *tfprotov5.ConfigureProviderRequest) *tfprotov6 } return &tfprotov6.ConfigureProviderRequest{ - Config: DynamicValue(in.Config), - TerraformVersion: in.TerraformVersion, + ClientCapabilities: ConfigureProviderClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + TerraformVersion: in.TerraformVersion, } } +func ConfigureProviderClientCapabilities(in *tfprotov5.ConfigureProviderClientCapabilities) *tfprotov6.ConfigureProviderClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ConfigureProviderClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ConfigureProviderResponse(in *tfprotov5.ConfigureProviderResponse) *tfprotov6.ConfigureProviderResponse { if in == nil { return nil @@ -91,6 +104,18 @@ func DataSourceMetadata(in tfprotov5.DataSourceMetadata) tfprotov6.DataSourceMet } } +func Deferred(in *tfprotov5.Deferred) *tfprotov6.Deferred { + if in == nil { + return nil + } + + resp := &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReason(in.Reason), + } + + return resp +} + func Diagnostics(in []*tfprotov5.Diagnostic) []*tfprotov6.Diagnostic { if in == nil { return nil @@ -301,9 +326,22 @@ func ImportResourceStateRequest(in *tfprotov5.ImportResourceStateRequest) *tfpro } return &tfprotov6.ImportResourceStateRequest{ - ID: in.ID, - TypeName: in.TypeName, + ClientCapabilities: ImportResourceStateClientCapabilities(in.ClientCapabilities), + ID: in.ID, + TypeName: in.TypeName, + } +} + +func ImportResourceStateClientCapabilities(in *tfprotov5.ImportResourceStateClientCapabilities) *tfprotov6.ImportResourceStateClientCapabilities { + if in == nil { + return nil } + + resp := &tfprotov6.ImportResourceStateClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp } func ImportResourceStateResponse(in *tfprotov5.ImportResourceStateResponse) *tfprotov6.ImportResourceStateResponse { @@ -312,6 +350,7 @@ func ImportResourceStateResponse(in *tfprotov5.ImportResourceStateResponse) *tfp } return &tfprotov6.ImportResourceStateResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), ImportedResources: ImportedResources(in.ImportedResources), } @@ -373,21 +412,35 @@ func PlanResourceChangeRequest(in *tfprotov5.PlanResourceChangeRequest) *tfproto } return &tfprotov6.PlanResourceChangeRequest{ - Config: DynamicValue(in.Config), - PriorPrivate: in.PriorPrivate, - PriorState: DynamicValue(in.PriorState), - ProposedNewState: DynamicValue(in.ProposedNewState), - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: PlanResourceChangeClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + PriorPrivate: in.PriorPrivate, + PriorState: DynamicValue(in.PriorState), + ProposedNewState: DynamicValue(in.ProposedNewState), + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func PlanResourceChangeClientCapabilities(in *tfprotov5.PlanResourceChangeClientCapabilities) *tfprotov6.PlanResourceChangeClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.PlanResourceChangeClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func PlanResourceChangeResponse(in *tfprotov5.PlanResourceChangeResponse) *tfprotov6.PlanResourceChangeResponse { if in == nil { return nil } return &tfprotov6.PlanResourceChangeResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), PlannedPrivate: in.PlannedPrivate, PlannedState: DynamicValue(in.PlannedState), @@ -412,18 +465,32 @@ func ReadDataSourceRequest(in *tfprotov5.ReadDataSourceRequest) *tfprotov6.ReadD return nil } return &tfprotov6.ReadDataSourceRequest{ - Config: DynamicValue(in.Config), - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: ReadDataSourceClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func ReadDataSourceClientCapabilities(in *tfprotov5.ReadDataSourceClientCapabilities) *tfprotov6.ReadDataSourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ReadDataSourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ReadDataSourceResponse(in *tfprotov5.ReadDataSourceResponse) *tfprotov6.ReadDataSourceResponse { if in == nil { return nil } return &tfprotov6.ReadDataSourceResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), State: DynamicValue(in.State), } @@ -435,19 +502,33 @@ func ReadResourceRequest(in *tfprotov5.ReadResourceRequest) *tfprotov6.ReadResou } return &tfprotov6.ReadResourceRequest{ - CurrentState: DynamicValue(in.CurrentState), - Private: in.Private, - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: ReadResourceClientCapabilities(in.ClientCapabilities), + CurrentState: DynamicValue(in.CurrentState), + Private: in.Private, + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func ReadResourceClientCapabilities(in *tfprotov5.ReadResourceClientCapabilities) *tfprotov6.ReadResourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ReadResourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ReadResourceResponse(in *tfprotov5.ReadResourceResponse) *tfprotov6.ReadResourceResponse { if in == nil { return nil } return &tfprotov6.ReadResourceResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), NewState: DynamicValue(in.NewState), Private: in.Private, diff --git a/internal/tfprotov5tov6/tfprotov5tov6_test.go b/internal/tfprotov5tov6/tfprotov5tov6_test.go index cbff48b..1e15d90 100644 --- a/internal/tfprotov5tov6/tfprotov5tov6_test.go +++ b/internal/tfprotov5tov6/tfprotov5tov6_test.go @@ -303,6 +303,22 @@ func TestConfigureProviderRequest(t *testing.T) { TerraformVersion: "1.2.3", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov5.ConfigureProviderRequest{ + Config: &testTfprotov5DynamicValue, + TerraformVersion: "1.2.3", + ClientCapabilities: &tfprotov5.ConfigureProviderClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov6.ConfigureProviderRequest{ + Config: &testTfprotov6DynamicValue, + TerraformVersion: "1.2.3", + ClientCapabilities: &tfprotov6.ConfigureProviderClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -899,6 +915,22 @@ func TestImportResourceStateRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov5.ImportResourceStateRequest{ + ID: "test-id", + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov6.ImportResourceStateRequest{ + ID: "test-id", + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -949,6 +981,34 @@ func TestImportResourceStateResponse(t *testing.T) { }, }, }, + "deferred-reason": { + in: &tfprotov5.ImportResourceStateResponse{ + Diagnostics: testTfprotov5Diagnostics, + ImportedResources: []*tfprotov5.ImportedResource{ + { + Private: testBytes, + State: &testTfprotov5DynamicValue, + TypeName: "test_resource1", + }, + }, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov6.ImportResourceStateResponse{ + Diagnostics: testTfprotov6Diagnostics, + ImportedResources: []*tfprotov6.ImportedResource{ + { + Private: testBytes, + State: &testTfprotov6DynamicValue, + TypeName: "test_resource1", + }, + }, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1160,6 +1220,30 @@ func TestPlanResourceChangeRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov5.PlanResourceChangeRequest{ + Config: &testTfprotov5DynamicValue, + PriorPrivate: testBytes, + PriorState: &testTfprotov5DynamicValue, + ProposedNewState: &testTfprotov5DynamicValue, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov6.PlanResourceChangeRequest{ + Config: &testTfprotov6DynamicValue, + PriorPrivate: testBytes, + PriorState: &testTfprotov6DynamicValue, + ProposedNewState: &testTfprotov6DynamicValue, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1208,6 +1292,32 @@ func TestPlanResourceChangeResponse(t *testing.T) { UnsafeToUseLegacyTypeSystem: true, }, }, + "deferred-reason": { + in: &tfprotov5.PlanResourceChangeResponse{ + Diagnostics: testTfprotov5Diagnostics, + PlannedPrivate: testBytes, + PlannedState: &testTfprotov5DynamicValue, + RequiresReplace: []*tftypes.AttributePath{ + tftypes.NewAttributePath().WithAttributeName("test"), + }, + UnsafeToUseLegacyTypeSystem: true, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov6.PlanResourceChangeResponse{ + Diagnostics: testTfprotov6Diagnostics, + PlannedPrivate: testBytes, + PlannedState: &testTfprotov6DynamicValue, + RequiresReplace: []*tftypes.AttributePath{ + tftypes.NewAttributePath().WithAttributeName("test"), + }, + UnsafeToUseLegacyTypeSystem: true, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1286,6 +1396,24 @@ func TestReadDataSourceRequest(t *testing.T) { TypeName: "test_data_source", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov5.ReadDataSourceRequest{ + Config: &testTfprotov5DynamicValue, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_data_source", + ClientCapabilities: &tfprotov5.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov6.ReadDataSourceRequest{ + Config: &testTfprotov6DynamicValue, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_data_source", + ClientCapabilities: &tfprotov6.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1324,6 +1452,22 @@ func TestReadDataSourceResponse(t *testing.T) { State: &testTfprotov6DynamicValue, }, }, + "deferred-reason": { + in: &tfprotov5.ReadDataSourceResponse{ + Diagnostics: testTfprotov5Diagnostics, + State: &testTfprotov5DynamicValue, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov6.ReadDataSourceResponse{ + Diagnostics: testTfprotov6Diagnostics, + State: &testTfprotov6DynamicValue, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1366,6 +1510,26 @@ func TestReadResourceRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov5.ReadResourceRequest{ + CurrentState: &testTfprotov5DynamicValue, + Private: testBytes, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov6.ReadResourceRequest{ + CurrentState: &testTfprotov6DynamicValue, + Private: testBytes, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1406,6 +1570,24 @@ func TestReadResourceResponse(t *testing.T) { Private: testBytes, }, }, + "deferred-reason": { + in: &tfprotov5.ReadResourceResponse{ + Diagnostics: testTfprotov5Diagnostics, + NewState: &testTfprotov5DynamicValue, + Private: testBytes, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov6.ReadResourceResponse{ + Diagnostics: testTfprotov6Diagnostics, + NewState: &testTfprotov6DynamicValue, + Private: testBytes, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { diff --git a/internal/tfprotov6tov5/tfprotov6tov5.go b/internal/tfprotov6tov5/tfprotov6tov5.go index 8091b23..24846dc 100644 --- a/internal/tfprotov6tov5/tfprotov6tov5.go +++ b/internal/tfprotov6tov5/tfprotov6tov5.go @@ -75,11 +75,24 @@ func ConfigureProviderRequest(in *tfprotov6.ConfigureProviderRequest) *tfprotov5 } return &tfprotov5.ConfigureProviderRequest{ - Config: DynamicValue(in.Config), - TerraformVersion: in.TerraformVersion, + ClientCapabilities: ConfigureProviderClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + TerraformVersion: in.TerraformVersion, } } +func ConfigureProviderClientCapabilities(in *tfprotov6.ConfigureProviderClientCapabilities) *tfprotov5.ConfigureProviderClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ConfigureProviderClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ConfigureProviderResponse(in *tfprotov6.ConfigureProviderResponse) *tfprotov5.ConfigureProviderResponse { if in == nil { return nil @@ -96,6 +109,18 @@ func DataSourceMetadata(in tfprotov6.DataSourceMetadata) tfprotov5.DataSourceMet } } +func Deferred(in *tfprotov6.Deferred) *tfprotov5.Deferred { + if in == nil { + return nil + } + + resp := &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReason(in.Reason), + } + + return resp +} + func Diagnostics(in []*tfprotov6.Diagnostic) []*tfprotov5.Diagnostic { if in == nil { return nil @@ -329,9 +354,22 @@ func ImportResourceStateRequest(in *tfprotov6.ImportResourceStateRequest) *tfpro } return &tfprotov5.ImportResourceStateRequest{ - ID: in.ID, - TypeName: in.TypeName, + ClientCapabilities: ImportResourceStateClientCapabilities(in.ClientCapabilities), + ID: in.ID, + TypeName: in.TypeName, + } +} + +func ImportResourceStateClientCapabilities(in *tfprotov6.ImportResourceStateClientCapabilities) *tfprotov5.ImportResourceStateClientCapabilities { + if in == nil { + return nil } + + resp := &tfprotov5.ImportResourceStateClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp } func ImportResourceStateResponse(in *tfprotov6.ImportResourceStateResponse) *tfprotov5.ImportResourceStateResponse { @@ -340,6 +378,7 @@ func ImportResourceStateResponse(in *tfprotov6.ImportResourceStateResponse) *tfp } return &tfprotov5.ImportResourceStateResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), ImportedResources: ImportedResources(in.ImportedResources), } @@ -400,21 +439,35 @@ func PlanResourceChangeRequest(in *tfprotov6.PlanResourceChangeRequest) *tfproto return nil } return &tfprotov5.PlanResourceChangeRequest{ - Config: DynamicValue(in.Config), - PriorPrivate: in.PriorPrivate, - PriorState: DynamicValue(in.PriorState), - ProposedNewState: DynamicValue(in.ProposedNewState), - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: PlanResourceChangeClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + PriorPrivate: in.PriorPrivate, + PriorState: DynamicValue(in.PriorState), + ProposedNewState: DynamicValue(in.ProposedNewState), + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func PlanResourceChangeClientCapabilities(in *tfprotov6.PlanResourceChangeClientCapabilities) *tfprotov5.PlanResourceChangeClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.PlanResourceChangeClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func PlanResourceChangeResponse(in *tfprotov6.PlanResourceChangeResponse) *tfprotov5.PlanResourceChangeResponse { if in == nil { return nil } return &tfprotov5.PlanResourceChangeResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), PlannedPrivate: in.PlannedPrivate, PlannedState: DynamicValue(in.PlannedState), @@ -460,18 +513,32 @@ func ReadDataSourceRequest(in *tfprotov6.ReadDataSourceRequest) *tfprotov5.ReadD return nil } return &tfprotov5.ReadDataSourceRequest{ - Config: DynamicValue(in.Config), - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: ReadDataSourceClientCapabilities(in.ClientCapabilities), + Config: DynamicValue(in.Config), + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func ReadDataSourceClientCapabilities(in *tfprotov6.ReadDataSourceClientCapabilities) *tfprotov5.ReadDataSourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ReadDataSourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ReadDataSourceResponse(in *tfprotov6.ReadDataSourceResponse) *tfprotov5.ReadDataSourceResponse { if in == nil { return nil } return &tfprotov5.ReadDataSourceResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), State: DynamicValue(in.State), } @@ -483,19 +550,33 @@ func ReadResourceRequest(in *tfprotov6.ReadResourceRequest) *tfprotov5.ReadResou } return &tfprotov5.ReadResourceRequest{ - CurrentState: DynamicValue(in.CurrentState), - Private: in.Private, - ProviderMeta: DynamicValue(in.ProviderMeta), - TypeName: in.TypeName, + ClientCapabilities: ReadResourceClientCapabilities(in.ClientCapabilities), + CurrentState: DynamicValue(in.CurrentState), + Private: in.Private, + ProviderMeta: DynamicValue(in.ProviderMeta), + TypeName: in.TypeName, } } +func ReadResourceClientCapabilities(in *tfprotov6.ReadResourceClientCapabilities) *tfprotov5.ReadResourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ReadResourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + func ReadResourceResponse(in *tfprotov6.ReadResourceResponse) *tfprotov5.ReadResourceResponse { if in == nil { return nil } return &tfprotov5.ReadResourceResponse{ + Deferred: Deferred(in.Deferred), Diagnostics: Diagnostics(in.Diagnostics), NewState: DynamicValue(in.NewState), Private: in.Private, diff --git a/internal/tfprotov6tov5/tfprotov6tov5_test.go b/internal/tfprotov6tov5/tfprotov6tov5_test.go index 6bc78fe..9252d42 100644 --- a/internal/tfprotov6tov5/tfprotov6tov5_test.go +++ b/internal/tfprotov6tov5/tfprotov6tov5_test.go @@ -305,6 +305,22 @@ func TestConfigureProviderRequest(t *testing.T) { TerraformVersion: "1.2.3", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov6.ConfigureProviderRequest{ + Config: &testTfprotov6DynamicValue, + TerraformVersion: "1.2.3", + ClientCapabilities: &tfprotov6.ConfigureProviderClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov5.ConfigureProviderRequest{ + Config: &testTfprotov5DynamicValue, + TerraformVersion: "1.2.3", + ClientCapabilities: &tfprotov5.ConfigureProviderClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1014,6 +1030,22 @@ func TestImportResourceStateRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov6.ImportResourceStateRequest{ + ID: "test-id", + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov5.ImportResourceStateRequest{ + ID: "test-id", + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1064,6 +1096,34 @@ func TestImportResourceStateResponse(t *testing.T) { }, }, }, + "deferred-reason": { + in: &tfprotov6.ImportResourceStateResponse{ + Diagnostics: testTfprotov6Diagnostics, + ImportedResources: []*tfprotov6.ImportedResource{ + { + Private: testBytes, + State: &testTfprotov6DynamicValue, + TypeName: "test_resource1", + }, + }, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov5.ImportResourceStateResponse{ + Diagnostics: testTfprotov5Diagnostics, + ImportedResources: []*tfprotov5.ImportedResource{ + { + Private: testBytes, + State: &testTfprotov5DynamicValue, + TypeName: "test_resource1", + }, + }, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1275,6 +1335,30 @@ func TestPlanResourceChangeRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov6.PlanResourceChangeRequest{ + Config: &testTfprotov6DynamicValue, + PriorPrivate: testBytes, + PriorState: &testTfprotov6DynamicValue, + ProposedNewState: &testTfprotov6DynamicValue, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov5.PlanResourceChangeRequest{ + Config: &testTfprotov5DynamicValue, + PriorPrivate: testBytes, + PriorState: &testTfprotov5DynamicValue, + ProposedNewState: &testTfprotov5DynamicValue, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1323,6 +1407,32 @@ func TestPlanResourceChangeResponse(t *testing.T) { UnsafeToUseLegacyTypeSystem: true, }, }, + "deferred-reason": { + in: &tfprotov6.PlanResourceChangeResponse{ + Diagnostics: testTfprotov6Diagnostics, + PlannedPrivate: testBytes, + PlannedState: &testTfprotov6DynamicValue, + RequiresReplace: []*tftypes.AttributePath{ + tftypes.NewAttributePath().WithAttributeName("test"), + }, + UnsafeToUseLegacyTypeSystem: true, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov5.PlanResourceChangeResponse{ + Diagnostics: testTfprotov5Diagnostics, + PlannedPrivate: testBytes, + PlannedState: &testTfprotov5DynamicValue, + RequiresReplace: []*tftypes.AttributePath{ + tftypes.NewAttributePath().WithAttributeName("test"), + }, + UnsafeToUseLegacyTypeSystem: true, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1475,6 +1585,24 @@ func TestReadDataSourceRequest(t *testing.T) { TypeName: "test_data_source", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov6.ReadDataSourceRequest{ + Config: &testTfprotov6DynamicValue, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_data_source", + ClientCapabilities: &tfprotov6.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov5.ReadDataSourceRequest{ + Config: &testTfprotov5DynamicValue, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_data_source", + ClientCapabilities: &tfprotov5.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1513,6 +1641,22 @@ func TestReadDataSourceResponse(t *testing.T) { State: &testTfprotov5DynamicValue, }, }, + "deferred-reason": { + in: &tfprotov6.ReadDataSourceResponse{ + Diagnostics: testTfprotov6Diagnostics, + State: &testTfprotov6DynamicValue, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov5.ReadDataSourceResponse{ + Diagnostics: testTfprotov5Diagnostics, + State: &testTfprotov5DynamicValue, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases { @@ -1555,6 +1699,26 @@ func TestReadResourceRequest(t *testing.T) { TypeName: "test_resource", }, }, + "client-capabilities-deferral-allowed": { + in: &tfprotov6.ReadResourceRequest{ + CurrentState: &testTfprotov6DynamicValue, + Private: testBytes, + ProviderMeta: &testTfprotov6DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov6.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + expected: &tfprotov5.ReadResourceRequest{ + CurrentState: &testTfprotov5DynamicValue, + Private: testBytes, + ProviderMeta: &testTfprotov5DynamicValue, + TypeName: "test_resource", + ClientCapabilities: &tfprotov5.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + }, } for name, testCase := range testCases { @@ -1595,6 +1759,24 @@ func TestReadResourceResponse(t *testing.T) { Private: testBytes, }, }, + "deferred-reason": { + in: &tfprotov6.ReadResourceResponse{ + Diagnostics: testTfprotov6Diagnostics, + NewState: &testTfprotov6DynamicValue, + Private: testBytes, + Deferred: &tfprotov6.Deferred{ + Reason: tfprotov6.DeferredReasonResourceConfigUnknown, + }, + }, + expected: &tfprotov5.ReadResourceResponse{ + Diagnostics: testTfprotov5Diagnostics, + NewState: &testTfprotov5DynamicValue, + Private: testBytes, + Deferred: &tfprotov5.Deferred{ + Reason: tfprotov5.DeferredReasonResourceConfigUnknown, + }, + }, + }, } for name, testCase := range testCases {