diff --git a/tfprotov5/client_capabilities.go b/tfprotov5/client_capabilities.go index 48bcb24c7..ba01cd8b8 100644 --- a/tfprotov5/client_capabilities.go +++ b/tfprotov5/client_capabilities.go @@ -3,10 +3,47 @@ package tfprotov5 -// ClientCapabilities allows Terraform to publish information regarding optionally supported -// protocol features, such as forward-compatible Terraform behavior changes. -type ClientCapabilities struct { - // DeferralAllowed signals that the Terraform client is able to +// ConfigureProviderClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ConfigureProvider RPC, +// such as forward-compatible Terraform behavior changes. +type ConfigureProviderClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ReadDataSourceClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ReadDataSource RPC, +// such as forward-compatible Terraform behavior changes. +type ReadDataSourceClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ReadResourceClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ReadResource RPC, +// such as forward-compatible Terraform behavior changes. +type ReadResourceClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// PlanResourceChangeClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the PlanResourceChange RPC, +// such as forward-compatible Terraform behavior changes. +type PlanResourceChangeClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ImportResourceStateClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ImportResourceState RPC, +// such as forward-compatible Terraform behavior changes. +type ImportResourceStateClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to // handle deferred responses from the provider. DeferralAllowed bool } diff --git a/tfprotov5/data_source.go b/tfprotov5/data_source.go index 49e1d9e2a..df1a2814d 100644 --- a/tfprotov5/data_source.go +++ b/tfprotov5/data_source.go @@ -88,9 +88,9 @@ type ReadDataSourceRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ReadDataSource RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ReadDataSourceClientCapabilities } // ReadDataSourceResponse is the response from the provider about the current diff --git a/tfprotov5/internal/fromproto/client_capabilities.go b/tfprotov5/internal/fromproto/client_capabilities.go index 07e67b709..94ddc3d43 100644 --- a/tfprotov5/internal/fromproto/client_capabilities.go +++ b/tfprotov5/internal/fromproto/client_capabilities.go @@ -8,12 +8,60 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" ) -func ClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ClientCapabilities { +func ConfigureProviderClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ConfigureProviderClientCapabilities { if in == nil { return nil } - resp := &tfprotov5.ClientCapabilities{ + resp := &tfprotov5.ConfigureProviderClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ReadDataSourceClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ReadDataSourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ReadDataSourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ReadResourceClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ReadResourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ReadResourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func PlanResourceChangeClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.PlanResourceChangeClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.PlanResourceChangeClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ImportResourceStateClientCapabilities(in *tfplugin5.ClientCapabilities) *tfprotov5.ImportResourceStateClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov5.ImportResourceStateClientCapabilities{ DeferralAllowed: in.DeferralAllowed, } diff --git a/tfprotov5/internal/fromproto/client_capabilities_test.go b/tfprotov5/internal/fromproto/client_capabilities_test.go index c315c18ec..c6c743824 100644 --- a/tfprotov5/internal/fromproto/client_capabilities_test.go +++ b/tfprotov5/internal/fromproto/client_capabilities_test.go @@ -12,12 +12,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5" ) -func TestClientCapabilities(t *testing.T) { +func TestConfigureProviderClientCapabilities(t *testing.T) { t.Parallel() testCases := map[string]struct { in *tfplugin5.ClientCapabilities - expected *tfprotov5.ClientCapabilities + expected *tfprotov5.ConfigureProviderClientCapabilities }{ "nil": { in: nil, @@ -25,13 +25,13 @@ func TestClientCapabilities(t *testing.T) { }, "zero": { in: &tfplugin5.ClientCapabilities{}, - expected: &tfprotov5.ClientCapabilities{}, + expected: &tfprotov5.ConfigureProviderClientCapabilities{}, }, "DeferralAllowed": { in: &tfplugin5.ClientCapabilities{ DeferralAllowed: true, }, - expected: &tfprotov5.ClientCapabilities{ + expected: &tfprotov5.ConfigureProviderClientCapabilities{ DeferralAllowed: true, }, }, @@ -43,7 +43,167 @@ func TestClientCapabilities(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - got := fromproto.ClientCapabilities(testCase.in) + got := fromproto.ConfigureProviderClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestReadDataSourceClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin5.ClientCapabilities + expected *tfprotov5.ReadDataSourceClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin5.ClientCapabilities{}, + expected: &tfprotov5.ReadDataSourceClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin5.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov5.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ReadDataSourceClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestReadResourceClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin5.ClientCapabilities + expected *tfprotov5.ReadResourceClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin5.ClientCapabilities{}, + expected: &tfprotov5.ReadResourceClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin5.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov5.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ReadResourceClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestPlanResourceChangeClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin5.ClientCapabilities + expected *tfprotov5.PlanResourceChangeClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin5.ClientCapabilities{}, + expected: &tfprotov5.PlanResourceChangeClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin5.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov5.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.PlanResourceChangeClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestImportResourceStateClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin5.ClientCapabilities + expected *tfprotov5.ImportResourceStateClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin5.ClientCapabilities{}, + expected: &tfprotov5.ImportResourceStateClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin5.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov5.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ImportResourceStateClientCapabilities(testCase.in) if diff := cmp.Diff(got, testCase.expected); diff != "" { t.Errorf("unexpected difference: %s", diff) diff --git a/tfprotov5/internal/fromproto/data_source.go b/tfprotov5/internal/fromproto/data_source.go index 7fbd338ab..385f48453 100644 --- a/tfprotov5/internal/fromproto/data_source.go +++ b/tfprotov5/internal/fromproto/data_source.go @@ -30,7 +30,7 @@ func ReadDataSourceRequest(in *tfplugin5.ReadDataSource_Request) *tfprotov5.Read Config: DynamicValue(in.Config), ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ReadDataSourceClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov5/internal/fromproto/data_source_test.go b/tfprotov5/internal/fromproto/data_source_test.go index 87b82b79e..68c8e440c 100644 --- a/tfprotov5/internal/fromproto/data_source_test.go +++ b/tfprotov5/internal/fromproto/data_source_test.go @@ -58,7 +58,7 @@ func TestReadDataSourceRequest(t *testing.T) { }, }, expected: &tfprotov5.ReadDataSourceRequest{ - ClientCapabilities: &tfprotov5.ClientCapabilities{ + ClientCapabilities: &tfprotov5.ReadDataSourceClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov5/internal/fromproto/provider.go b/tfprotov5/internal/fromproto/provider.go index f5c51e166..ac487800e 100644 --- a/tfprotov5/internal/fromproto/provider.go +++ b/tfprotov5/internal/fromproto/provider.go @@ -48,7 +48,7 @@ func ConfigureProviderRequest(in *tfplugin5.Configure_Request) *tfprotov5.Config resp := &tfprotov5.ConfigureProviderRequest{ Config: DynamicValue(in.Config), TerraformVersion: in.TerraformVersion, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ConfigureProviderClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov5/internal/fromproto/provider_test.go b/tfprotov5/internal/fromproto/provider_test.go index e82e2818a..3e01a75a9 100644 --- a/tfprotov5/internal/fromproto/provider_test.go +++ b/tfprotov5/internal/fromproto/provider_test.go @@ -114,7 +114,7 @@ func TestConfigureProviderRequest(t *testing.T) { }, }, expected: &tfprotov5.ConfigureProviderRequest{ - ClientCapabilities: &tfprotov5.ClientCapabilities{ + ClientCapabilities: &tfprotov5.ConfigureProviderClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov5/internal/fromproto/resource.go b/tfprotov5/internal/fromproto/resource.go index 977e5aa17..f531b4870 100644 --- a/tfprotov5/internal/fromproto/resource.go +++ b/tfprotov5/internal/fromproto/resource.go @@ -45,7 +45,7 @@ func ReadResourceRequest(in *tfplugin5.ReadResource_Request) *tfprotov5.ReadReso Private: in.Private, ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ReadResourceClientCapabilities(in.ClientCapabilities), } return resp @@ -63,7 +63,7 @@ func PlanResourceChangeRequest(in *tfplugin5.PlanResourceChange_Request) *tfprot ProposedNewState: DynamicValue(in.ProposedNewState), ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: PlanResourceChangeClientCapabilities(in.ClientCapabilities), } return resp @@ -94,7 +94,7 @@ func ImportResourceStateRequest(in *tfplugin5.ImportResourceState_Request) *tfpr resp := &tfprotov5.ImportResourceStateRequest{ TypeName: in.TypeName, ID: in.Id, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ImportResourceStateClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov5/internal/fromproto/resource_test.go b/tfprotov5/internal/fromproto/resource_test.go index f7fd3fbfa..bc01acb1d 100644 --- a/tfprotov5/internal/fromproto/resource_test.go +++ b/tfprotov5/internal/fromproto/resource_test.go @@ -130,7 +130,7 @@ func TestImportResourceStateRequest(t *testing.T) { }, }, expected: &tfprotov5.ImportResourceStateRequest{ - ClientCapabilities: &tfprotov5.ClientCapabilities{ + ClientCapabilities: &tfprotov5.ImportResourceStateClientCapabilities{ DeferralAllowed: true, }, }, @@ -302,7 +302,7 @@ func TestPlanResourceChangeRequest(t *testing.T) { }, }, expected: &tfprotov5.PlanResourceChangeRequest{ - ClientCapabilities: &tfprotov5.ClientCapabilities{ + ClientCapabilities: &tfprotov5.PlanResourceChangeClientCapabilities{ DeferralAllowed: true, }, }, @@ -378,7 +378,7 @@ func TestReadResourceRequest(t *testing.T) { }, }, expected: &tfprotov5.ReadResourceRequest{ - ClientCapabilities: &tfprotov5.ClientCapabilities{ + ClientCapabilities: &tfprotov5.ReadResourceClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov5/provider.go b/tfprotov5/provider.go index c73856b07..799f90238 100644 --- a/tfprotov5/provider.go +++ b/tfprotov5/provider.go @@ -209,9 +209,9 @@ type ConfigureProviderRequest struct { // null. Config *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ConfigureProvider RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ConfigureProviderClientCapabilities } // ConfigureProviderResponse represents a Terraform RPC response to the diff --git a/tfprotov5/resource.go b/tfprotov5/resource.go index 338a01bb9..9e50a0ce6 100644 --- a/tfprotov5/resource.go +++ b/tfprotov5/resource.go @@ -188,9 +188,9 @@ type ReadResourceRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ReadResource RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ReadResourceClientCapabilities } // ReadResourceResponse is the response from the provider about the current @@ -286,9 +286,9 @@ type PlanResourceChangeRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // PlanResourceChange RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *PlanResourceChangeClientCapabilities } // PlanResourceChangeResponse is the response from the provider about what the @@ -492,9 +492,9 @@ type ImportResourceStateRequest struct { // import. ID string - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ImportResourceState RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ImportResourceStateClientCapabilities } // ImportResourceStateResponse is the response from the provider about the diff --git a/tfprotov6/client_capabilities.go b/tfprotov6/client_capabilities.go index 2737d779e..b528c123a 100644 --- a/tfprotov6/client_capabilities.go +++ b/tfprotov6/client_capabilities.go @@ -3,10 +3,47 @@ package tfprotov6 -// ClientCapabilities allows Terraform to publish information regarding optionally supported -// protocol features, such as forward-compatible Terraform behavior changes. -type ClientCapabilities struct { - // DeferralAllowed signals that the Terraform client is able to +// ConfigureProviderClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ConfigureProvider RPC, +// such as forward-compatible Terraform behavior changes. +type ConfigureProviderClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ReadDataSourceClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ReadDataSource RPC, +// such as forward-compatible Terraform behavior changes. +type ReadDataSourceClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ReadResourceClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ReadResource RPC, +// such as forward-compatible Terraform behavior changes. +type ReadResourceClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// PlanResourceChangeClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the PlanResourceChange RPC, +// such as forward-compatible Terraform behavior changes. +type PlanResourceChangeClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to + // handle deferred responses from the provider. + DeferralAllowed bool +} + +// ImportResourceStateClientCapabilities allows Terraform to publish information +// regarding optionally supported protocol features for the ImportResourceState RPC, +// such as forward-compatible Terraform behavior changes. +type ImportResourceStateClientCapabilities struct { + // DeferralAllowed signals that the request from Terraform is able to // handle deferred responses from the provider. DeferralAllowed bool } diff --git a/tfprotov6/data_source.go b/tfprotov6/data_source.go index 239ccba68..bed6e3d52 100644 --- a/tfprotov6/data_source.go +++ b/tfprotov6/data_source.go @@ -88,9 +88,9 @@ type ReadDataSourceRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ReadDataSource RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ReadDataSourceClientCapabilities } // ReadDataSourceResponse is the response from the provider about the current diff --git a/tfprotov6/internal/fromproto/client_capabilities.go b/tfprotov6/internal/fromproto/client_capabilities.go index 559fedc2e..06238eac0 100644 --- a/tfprotov6/internal/fromproto/client_capabilities.go +++ b/tfprotov6/internal/fromproto/client_capabilities.go @@ -8,12 +8,60 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6" ) -func ClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.ClientCapabilities { +func ConfigureProviderClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.ConfigureProviderClientCapabilities { if in == nil { return nil } - resp := &tfprotov6.ClientCapabilities{ + resp := &tfprotov6.ConfigureProviderClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ReadDataSourceClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.ReadDataSourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ReadDataSourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ReadResourceClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.ReadResourceClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ReadResourceClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func PlanResourceChangeClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.PlanResourceChangeClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.PlanResourceChangeClientCapabilities{ + DeferralAllowed: in.DeferralAllowed, + } + + return resp +} + +func ImportResourceStateClientCapabilities(in *tfplugin6.ClientCapabilities) *tfprotov6.ImportResourceStateClientCapabilities { + if in == nil { + return nil + } + + resp := &tfprotov6.ImportResourceStateClientCapabilities{ DeferralAllowed: in.DeferralAllowed, } diff --git a/tfprotov6/internal/fromproto/client_capabilities_test.go b/tfprotov6/internal/fromproto/client_capabilities_test.go index 6910d8b60..1b446454e 100644 --- a/tfprotov6/internal/fromproto/client_capabilities_test.go +++ b/tfprotov6/internal/fromproto/client_capabilities_test.go @@ -12,12 +12,12 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6/internal/tfplugin6" ) -func TestClientCapabilities(t *testing.T) { +func TestConfigureProviderClientCapabilities(t *testing.T) { t.Parallel() testCases := map[string]struct { in *tfplugin6.ClientCapabilities - expected *tfprotov6.ClientCapabilities + expected *tfprotov6.ConfigureProviderClientCapabilities }{ "nil": { in: nil, @@ -25,13 +25,13 @@ func TestClientCapabilities(t *testing.T) { }, "zero": { in: &tfplugin6.ClientCapabilities{}, - expected: &tfprotov6.ClientCapabilities{}, + expected: &tfprotov6.ConfigureProviderClientCapabilities{}, }, "DeferralAllowed": { in: &tfplugin6.ClientCapabilities{ DeferralAllowed: true, }, - expected: &tfprotov6.ClientCapabilities{ + expected: &tfprotov6.ConfigureProviderClientCapabilities{ DeferralAllowed: true, }, }, @@ -43,7 +43,167 @@ func TestClientCapabilities(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - got := fromproto.ClientCapabilities(testCase.in) + got := fromproto.ConfigureProviderClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestReadDataSourceClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin6.ClientCapabilities + expected *tfprotov6.ReadDataSourceClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin6.ClientCapabilities{}, + expected: &tfprotov6.ReadDataSourceClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin6.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov6.ReadDataSourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ReadDataSourceClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestReadResourceClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin6.ClientCapabilities + expected *tfprotov6.ReadResourceClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin6.ClientCapabilities{}, + expected: &tfprotov6.ReadResourceClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin6.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov6.ReadResourceClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ReadResourceClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestPlanResourceChangeClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin6.ClientCapabilities + expected *tfprotov6.PlanResourceChangeClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin6.ClientCapabilities{}, + expected: &tfprotov6.PlanResourceChangeClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin6.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov6.PlanResourceChangeClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.PlanResourceChangeClientCapabilities(testCase.in) + + if diff := cmp.Diff(got, testCase.expected); diff != "" { + t.Errorf("unexpected difference: %s", diff) + } + }) + } +} + +func TestImportResourceStateClientCapabilities(t *testing.T) { + t.Parallel() + + testCases := map[string]struct { + in *tfplugin6.ClientCapabilities + expected *tfprotov6.ImportResourceStateClientCapabilities + }{ + "nil": { + in: nil, + expected: nil, + }, + "zero": { + in: &tfplugin6.ClientCapabilities{}, + expected: &tfprotov6.ImportResourceStateClientCapabilities{}, + }, + "DeferralAllowed": { + in: &tfplugin6.ClientCapabilities{ + DeferralAllowed: true, + }, + expected: &tfprotov6.ImportResourceStateClientCapabilities{ + DeferralAllowed: true, + }, + }, + } + + for name, testCase := range testCases { + name, testCase := name, testCase + + t.Run(name, func(t *testing.T) { + t.Parallel() + + got := fromproto.ImportResourceStateClientCapabilities(testCase.in) if diff := cmp.Diff(got, testCase.expected); diff != "" { t.Errorf("unexpected difference: %s", diff) diff --git a/tfprotov6/internal/fromproto/data_source.go b/tfprotov6/internal/fromproto/data_source.go index 560bc3625..85059f92a 100644 --- a/tfprotov6/internal/fromproto/data_source.go +++ b/tfprotov6/internal/fromproto/data_source.go @@ -30,7 +30,7 @@ func ReadDataSourceRequest(in *tfplugin6.ReadDataSource_Request) *tfprotov6.Read Config: DynamicValue(in.Config), ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ReadDataSourceClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov6/internal/fromproto/data_source_test.go b/tfprotov6/internal/fromproto/data_source_test.go index 545e5d83f..e17a5f60e 100644 --- a/tfprotov6/internal/fromproto/data_source_test.go +++ b/tfprotov6/internal/fromproto/data_source_test.go @@ -58,7 +58,7 @@ func TestReadDataSourceRequest(t *testing.T) { }, }, expected: &tfprotov6.ReadDataSourceRequest{ - ClientCapabilities: &tfprotov6.ClientCapabilities{ + ClientCapabilities: &tfprotov6.ReadDataSourceClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov6/internal/fromproto/provider.go b/tfprotov6/internal/fromproto/provider.go index 50d5283e9..99a6cc556 100644 --- a/tfprotov6/internal/fromproto/provider.go +++ b/tfprotov6/internal/fromproto/provider.go @@ -48,7 +48,7 @@ func ConfigureProviderRequest(in *tfplugin6.ConfigureProvider_Request) *tfprotov resp := &tfprotov6.ConfigureProviderRequest{ Config: DynamicValue(in.Config), TerraformVersion: in.TerraformVersion, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ConfigureProviderClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov6/internal/fromproto/provider_test.go b/tfprotov6/internal/fromproto/provider_test.go index 96ef8a4ce..5082cdebf 100644 --- a/tfprotov6/internal/fromproto/provider_test.go +++ b/tfprotov6/internal/fromproto/provider_test.go @@ -114,7 +114,7 @@ func TestConfigureProviderRequest(t *testing.T) { }, }, expected: &tfprotov6.ConfigureProviderRequest{ - ClientCapabilities: &tfprotov6.ClientCapabilities{ + ClientCapabilities: &tfprotov6.ConfigureProviderClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov6/internal/fromproto/resource.go b/tfprotov6/internal/fromproto/resource.go index 2d545e45e..24e336953 100644 --- a/tfprotov6/internal/fromproto/resource.go +++ b/tfprotov6/internal/fromproto/resource.go @@ -45,7 +45,7 @@ func ReadResourceRequest(in *tfplugin6.ReadResource_Request) *tfprotov6.ReadReso Private: in.Private, ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ReadResourceClientCapabilities(in.ClientCapabilities), } return resp @@ -63,7 +63,7 @@ func PlanResourceChangeRequest(in *tfplugin6.PlanResourceChange_Request) *tfprot ProposedNewState: DynamicValue(in.ProposedNewState), ProviderMeta: DynamicValue(in.ProviderMeta), TypeName: in.TypeName, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: PlanResourceChangeClientCapabilities(in.ClientCapabilities), } return resp @@ -94,7 +94,7 @@ func ImportResourceStateRequest(in *tfplugin6.ImportResourceState_Request) *tfpr resp := &tfprotov6.ImportResourceStateRequest{ TypeName: in.TypeName, ID: in.Id, - ClientCapabilities: ClientCapabilities(in.ClientCapabilities), + ClientCapabilities: ImportResourceStateClientCapabilities(in.ClientCapabilities), } return resp diff --git a/tfprotov6/internal/fromproto/resource_test.go b/tfprotov6/internal/fromproto/resource_test.go index 1c8d442ea..4beff671f 100644 --- a/tfprotov6/internal/fromproto/resource_test.go +++ b/tfprotov6/internal/fromproto/resource_test.go @@ -130,7 +130,7 @@ func TestImportResourceStateRequest(t *testing.T) { }, }, expected: &tfprotov6.ImportResourceStateRequest{ - ClientCapabilities: &tfprotov6.ClientCapabilities{ + ClientCapabilities: &tfprotov6.ImportResourceStateClientCapabilities{ DeferralAllowed: true, }, }, @@ -302,7 +302,7 @@ func TestPlanResourceChangeRequest(t *testing.T) { }, }, expected: &tfprotov6.PlanResourceChangeRequest{ - ClientCapabilities: &tfprotov6.ClientCapabilities{ + ClientCapabilities: &tfprotov6.PlanResourceChangeClientCapabilities{ DeferralAllowed: true, }, }, @@ -378,7 +378,7 @@ func TestReadResourceRequest(t *testing.T) { }, }, expected: &tfprotov6.ReadResourceRequest{ - ClientCapabilities: &tfprotov6.ClientCapabilities{ + ClientCapabilities: &tfprotov6.ReadResourceClientCapabilities{ DeferralAllowed: true, }, }, diff --git a/tfprotov6/provider.go b/tfprotov6/provider.go index a081e186b..a5185138f 100644 --- a/tfprotov6/provider.go +++ b/tfprotov6/provider.go @@ -209,9 +209,9 @@ type ConfigureProviderRequest struct { // null. Config *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ConfigureProvider RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ConfigureProviderClientCapabilities } // ConfigureProviderResponse represents a Terraform RPC response to the diff --git a/tfprotov6/resource.go b/tfprotov6/resource.go index 38ea091bc..bf1a6e387 100644 --- a/tfprotov6/resource.go +++ b/tfprotov6/resource.go @@ -185,9 +185,9 @@ type ReadResourceRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ReadResource RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ReadResourceClientCapabilities } // ReadResourceResponse is the response from the provider about the current @@ -283,9 +283,9 @@ type PlanResourceChangeRequest struct { // This configuration will have known values for all fields. ProviderMeta *DynamicValue - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // PlanResourceChange RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *PlanResourceChangeClientCapabilities } // PlanResourceChangeResponse is the response from the provider about what the @@ -489,9 +489,9 @@ type ImportResourceStateRequest struct { // import. ID string - // ClientCapabilities defines optionally supported protocol features for - // the Terraform client, such as forward-compatible Terraform behavior changes. - ClientCapabilities *ClientCapabilities + // ClientCapabilities defines optionally supported protocol features for the + // ImportResourceState RPC, such as forward-compatible Terraform behavior changes. + ClientCapabilities *ImportResourceStateClientCapabilities } // ImportResourceStateResponse is the response from the provider about the