From 421fe3580fda0e55a68ae62ca47a1e9de7bf3e0e Mon Sep 17 00:00:00 2001 From: Daniel Banck Date: Fri, 16 May 2025 13:55:12 +0200 Subject: [PATCH] Check GetResourceIdentitySchemas diagnostics and return early (#36999) --- internal/plugin/grpc_provider.go | 5 ++++ internal/plugin/grpc_provider_test.go | 34 ++++++++++++++++++++++++++ internal/plugin6/grpc_provider.go | 5 ++++ internal/plugin6/grpc_provider_test.go | 34 ++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) diff --git a/internal/plugin/grpc_provider.go b/internal/plugin/grpc_provider.go index 950928acd6..66dc3a91a7 100644 --- a/internal/plugin/grpc_provider.go +++ b/internal/plugin/grpc_provider.go @@ -142,6 +142,11 @@ func (p *GRPCProvider) GetProviderSchema() providers.GetProviderSchemaResponse { } } + resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(identResp.Diagnostics)) + if resp.Diagnostics.HasErrors() { + return resp + } + resp.Provider = convert.ProtoToProviderSchema(protoResp.Provider, nil) if protoResp.ProviderMeta == nil { logger.Debug("No provider meta schema returned") diff --git a/internal/plugin/grpc_provider_test.go b/internal/plugin/grpc_provider_test.go index c34052ec7e..df91a942bd 100644 --- a/internal/plugin/grpc_provider_test.go +++ b/internal/plugin/grpc_provider_test.go @@ -272,6 +272,40 @@ func TestGRPCProvider_GetSchema_IdentityUnimplemented(t *testing.T) { checkDiags(t, resp.Diagnostics) } +func TestGRPCProvider_GetSchema_IdentityErrorDiagnostic(t *testing.T) { + ctrl := gomock.NewController(t) + client := mockproto.NewMockProviderClient(ctrl) + + client.EXPECT().GetSchema( + gomock.Any(), + gomock.Any(), + gomock.Any(), + ).Return(providerProtoSchema(), nil) + + client.EXPECT().GetResourceIdentitySchemas( + gomock.Any(), + gomock.Any(), + gomock.Any(), + ).Return(&proto.GetResourceIdentitySchemas_Response{ + Diagnostics: []*proto.Diagnostic{ + { + Severity: proto.Diagnostic_ERROR, + Summary: "error summary", + Detail: "error detail", + }, + }, + IdentitySchemas: map[string]*proto.ResourceIdentitySchema{}, + }, nil) + + p := &GRPCProvider{ + client: client, + } + + resp := p.GetProviderSchema() + + checkDiagsHasError(t, resp.Diagnostics) +} + func TestGRPCProvider_GetResourceIdentitySchemas(t *testing.T) { ctrl := gomock.NewController(t) client := mockproto.NewMockProviderClient(ctrl) diff --git a/internal/plugin6/grpc_provider.go b/internal/plugin6/grpc_provider.go index 5b7113f613..7bb85de437 100644 --- a/internal/plugin6/grpc_provider.go +++ b/internal/plugin6/grpc_provider.go @@ -142,6 +142,11 @@ func (p *GRPCProvider) GetProviderSchema() providers.GetProviderSchemaResponse { } } + resp.Diagnostics = resp.Diagnostics.Append(convert.ProtoToDiagnostics(identResp.Diagnostics)) + if resp.Diagnostics.HasErrors() { + return resp + } + resp.Provider = convert.ProtoToProviderSchema(protoResp.Provider, nil) if protoResp.ProviderMeta == nil { logger.Debug("No provider meta schema returned") diff --git a/internal/plugin6/grpc_provider_test.go b/internal/plugin6/grpc_provider_test.go index 0c86d7956d..07e07c2049 100644 --- a/internal/plugin6/grpc_provider_test.go +++ b/internal/plugin6/grpc_provider_test.go @@ -279,6 +279,40 @@ func TestGRPCProvider_GetSchema_IdentityUnimplemented(t *testing.T) { checkDiags(t, resp.Diagnostics) } +func TestGRPCProvider_GetSchema_IdentityErrorDiagnostic(t *testing.T) { + ctrl := gomock.NewController(t) + client := mockproto.NewMockProviderClient(ctrl) + + client.EXPECT().GetProviderSchema( + gomock.Any(), + gomock.Any(), + gomock.Any(), + ).Return(providerProtoSchema(), nil) + + client.EXPECT().GetResourceIdentitySchemas( + gomock.Any(), + gomock.Any(), + gomock.Any(), + ).Return(&proto.GetResourceIdentitySchemas_Response{ + Diagnostics: []*proto.Diagnostic{ + { + Severity: proto.Diagnostic_ERROR, + Summary: "error summary", + Detail: "error detail", + }, + }, + IdentitySchemas: map[string]*proto.ResourceIdentitySchema{}, + }, nil) + + p := &GRPCProvider{ + client: client, + } + + resp := p.GetProviderSchema() + + checkDiagsHasError(t, resp.Diagnostics) +} + func TestGRPCProvider_GetResourceIdentitySchemas(t *testing.T) { ctrl := gomock.NewController(t) client := mockproto.NewMockProviderClient(ctrl)