Skip to content

Commit

Permalink
safely skip server if it does not implement ProviderServerWithResourc…
Browse files Browse the repository at this point in the history
…eIdentity
  • Loading branch information
ansgarm committed Feb 13, 2025
1 parent 6e5b920 commit 656dec9
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions tf5muxserver/mux_server_GetResourceIdentitySchemas.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,28 @@ func (s *muxServer) GetResourceIdentitySchemas(ctx context.Context, req *tfproto

// TODO: Remove and call server.GetResourceIdentitySchemas below directly once interface becomes required.
//nolint:staticcheck // Intentionally verifying interface implementation
resourceIdentityServer, err := server.(tfprotov5.ProviderServerWithResourceIdentity).GetResourceIdentitySchemas(ctx, req)
resourceIdentityServer, ok := server.(tfprotov5.ProviderServerWithResourceIdentity)

if !ok {
resp.Diagnostics = append(resp.Diagnostics, &tfprotov5.Diagnostic{
Severity: tfprotov5.DiagnosticSeverityError,
Summary: "GetResourceIdentitySchemas Not Implemented",
Detail: "A GetResourceIdentitySchemas call was received by the provider, however the provider does not implement GetResourceIdentitySchemas. " +
"Either upgrade the provider to a version that implements GetResourceIdentitySchemas or this is a bug in Terraform that should be reported to the Terraform maintainers.",
})

continue
}

resourceIdentitySchemas, err := resourceIdentityServer.GetResourceIdentitySchemas(ctx, req)

if err != nil {
return resp, fmt.Errorf("error calling GetResourceIdentitySchemas for %T: %w", server, err)
}

resp.Diagnostics = append(resp.Diagnostics, resourceIdentityServer.Diagnostics...)
resp.Diagnostics = append(resp.Diagnostics, resourceIdentitySchemas.Diagnostics...)

for resourceIdentityType, schema := range resourceIdentityServer.IdentitySchemas {
for resourceIdentityType, schema := range resourceIdentitySchemas.IdentitySchemas {
if _, ok := resp.IdentitySchemas[resourceIdentityType]; ok {
resp.Diagnostics = append(resp.Diagnostics, resourceIdentityDuplicateError(resourceIdentityType))

Expand Down

0 comments on commit 656dec9

Please sign in to comment.