diff --git a/tf5muxserver/mux_server.go b/tf5muxserver/mux_server.go index 17a9139..6057fe8 100644 --- a/tf5muxserver/mux_server.go +++ b/tf5muxserver/mux_server.go @@ -23,12 +23,6 @@ type muxServer struct { // Underlying servers for requests that should be handled by all servers servers []tfprotov5.ProviderServer - // Mux server capabilities use a logical OR of each of the capabilities - // across all servers and is cached during server creation. Individual - // RPC handlers check against resourceCapabilities, which aligns to the - // capabilities of the server for the particular resource type. - serverCapabilities *tfprotov5.ServerCapabilities - // Server errors are cached during server creation and deferred until // the GetProviderSchema call. This is to prevent confusing Terraform CLI // errors about the plugin not starting properly, which do not display the @@ -73,7 +67,6 @@ func NewMuxServer(ctx context.Context, servers ...func() tfprotov5.ProviderServe resources: make(map[string]tfprotov5.ProviderServer), resourceCapabilities: make(map[string]*tfprotov5.ServerCapabilities), resourceSchemas: make(map[string]*tfprotov5.Schema), - serverCapabilities: &tfprotov5.ServerCapabilities{}, } for _, serverFunc := range servers { @@ -114,13 +107,6 @@ func NewMuxServer(ctx context.Context, servers ...func() tfprotov5.ProviderServe } } - // Use logical OR across server capabilities. - if resp.ServerCapabilities != nil { - if resp.ServerCapabilities.PlanDestroy { - result.serverCapabilities.PlanDestroy = true - } - } - for resourceType, schema := range resp.ResourceSchemas { if _, ok := result.resources[resourceType]; ok { result.serverResourceSchemaDuplicates = append(result.serverResourceSchemaDuplicates, resourceType) diff --git a/tf5muxserver/mux_server_GetProviderSchema.go b/tf5muxserver/mux_server_GetProviderSchema.go index 6a133a7..6455178 100644 --- a/tf5muxserver/mux_server_GetProviderSchema.go +++ b/tf5muxserver/mux_server_GetProviderSchema.go @@ -18,11 +18,17 @@ func (s muxServer) GetProviderSchema(ctx context.Context, req *tfprotov5.GetProv logging.MuxTrace(ctx, "serving cached schema information") resp := &tfprotov5.GetProviderSchemaResponse{ - Provider: s.providerSchema, - ResourceSchemas: s.resourceSchemas, - DataSourceSchemas: s.dataSourceSchemas, - ProviderMeta: s.providerMetaSchema, - ServerCapabilities: s.serverCapabilities, + Provider: s.providerSchema, + ResourceSchemas: s.resourceSchemas, + DataSourceSchemas: s.dataSourceSchemas, + ProviderMeta: s.providerMetaSchema, + + // Always announce all ServerCapabilities. Individual capabilities are + // handled in their respective RPCs to protect downstream servers if + // they are not compatible with a capability. + ServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, } for _, diff := range s.serverProviderSchemaDifferences { diff --git a/tf5muxserver/mux_server_GetProviderSchema_test.go b/tf5muxserver/mux_server_GetProviderSchema_test.go index 6faedf9..780dcae 100644 --- a/tf5muxserver/mux_server_GetProviderSchema_test.go +++ b/tf5muxserver/mux_server_GetProviderSchema_test.go @@ -417,6 +417,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, }, + expectedServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, "duplicate-data-source-type": { servers: []func() tfprotov5.ProviderServer{ @@ -444,6 +447,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + expectedServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, "duplicate-resource-type": { servers: []func() tfprotov5.ProviderServer{ @@ -471,6 +477,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { expectedResourceSchemas: map[string]*tfprotov5.Schema{ "test_foo": {}, }, + expectedServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, "provider-mismatch": { servers: []func() tfprotov5.ProviderServer{ @@ -546,6 +555,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + expectedServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, "provider-meta-mismatch": { servers: []func() tfprotov5.ProviderServer{ @@ -621,6 +633,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + expectedServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, "server-capabilities": { servers: []func() tfprotov5.ProviderServer{ diff --git a/tf6muxserver/mux_server.go b/tf6muxserver/mux_server.go index 6b5259a..69f63b9 100644 --- a/tf6muxserver/mux_server.go +++ b/tf6muxserver/mux_server.go @@ -23,12 +23,6 @@ type muxServer struct { // Underlying servers for requests that should be handled by all servers servers []tfprotov6.ProviderServer - // Mux server capabilities use a logical OR of each of the capabilities - // across all servers and is cached during server creation. Individual - // RPC handlers check against resourceCapabilities, which aligns to the - // capabilities of the server for the particular resource type. - serverCapabilities *tfprotov6.ServerCapabilities - // Server errors are cached during server creation and deferred until // the GetProviderSchema call. This is to prevent confusing Terraform CLI // errors about the plugin not starting properly, which do not display the @@ -73,7 +67,6 @@ func NewMuxServer(ctx context.Context, servers ...func() tfprotov6.ProviderServe resources: make(map[string]tfprotov6.ProviderServer), resourceCapabilities: make(map[string]*tfprotov6.ServerCapabilities), resourceSchemas: make(map[string]*tfprotov6.Schema), - serverCapabilities: &tfprotov6.ServerCapabilities{}, } for _, serverFunc := range servers { @@ -114,13 +107,6 @@ func NewMuxServer(ctx context.Context, servers ...func() tfprotov6.ProviderServe } } - // Use logical OR across server capabilities. - if resp.ServerCapabilities != nil { - if resp.ServerCapabilities.PlanDestroy { - result.serverCapabilities.PlanDestroy = true - } - } - for resourceType, schema := range resp.ResourceSchemas { if _, ok := result.resources[resourceType]; ok { result.serverResourceSchemaDuplicates = append(result.serverResourceSchemaDuplicates, resourceType) diff --git a/tf6muxserver/mux_server_GetProviderSchema.go b/tf6muxserver/mux_server_GetProviderSchema.go index e32bbeb..7d1bcdb 100644 --- a/tf6muxserver/mux_server_GetProviderSchema.go +++ b/tf6muxserver/mux_server_GetProviderSchema.go @@ -18,11 +18,17 @@ func (s muxServer) GetProviderSchema(ctx context.Context, req *tfprotov6.GetProv logging.MuxTrace(ctx, "serving cached schema information") resp := &tfprotov6.GetProviderSchemaResponse{ - Provider: s.providerSchema, - ResourceSchemas: s.resourceSchemas, - DataSourceSchemas: s.dataSourceSchemas, - ProviderMeta: s.providerMetaSchema, - ServerCapabilities: s.serverCapabilities, + Provider: s.providerSchema, + ResourceSchemas: s.resourceSchemas, + DataSourceSchemas: s.dataSourceSchemas, + ProviderMeta: s.providerMetaSchema, + + // Always announce all ServerCapabilities. Individual capabilities are + // handled in their respective RPCs to protect downstream servers if + // they are not compatible with a capability. + ServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, } for _, diff := range s.serverProviderSchemaDifferences { diff --git a/tf6muxserver/mux_server_GetProviderSchema_test.go b/tf6muxserver/mux_server_GetProviderSchema_test.go index 0ced513..412909e 100644 --- a/tf6muxserver/mux_server_GetProviderSchema_test.go +++ b/tf6muxserver/mux_server_GetProviderSchema_test.go @@ -417,6 +417,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, }, + expectedServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, "duplicate-data-source-type": { servers: []func() tfprotov6.ProviderServer{ @@ -444,6 +447,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + expectedServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, "duplicate-resource-type": { servers: []func() tfprotov6.ProviderServer{ @@ -471,6 +477,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { expectedResourceSchemas: map[string]*tfprotov6.Schema{ "test_foo": {}, }, + expectedServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, "provider-mismatch": { servers: []func() tfprotov6.ProviderServer{ @@ -546,6 +555,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + expectedServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, "provider-meta-mismatch": { servers: []func() tfprotov6.ProviderServer{ @@ -621,6 +633,9 @@ func TestMuxServerGetProviderSchema(t *testing.T) { }, }, expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + expectedServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, "server-capabilities": { servers: []func() tfprotov6.ProviderServer{