Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion stackit/internal/services/iaas/keypair/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package keypair

import (
"context"
"errors"
"fmt"
"net/http"

Expand Down Expand Up @@ -130,8 +131,14 @@ func (r *keyPairDataSource) Read(ctx context.Context, req datasource.ReadRequest

keypairResp, err := r.client.GetKeyPair(ctx, name).Execute()
if err != nil {
oapiErr, ok := err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
var oapiErr *oapierror.GenericOpenAPIError
ok := errors.As(err, &oapiErr)
if ok && oapiErr.StatusCode == http.StatusNotFound {
summary := fmt.Sprintf("Key Pair with name %q does not exists", name)
description := fmt.Sprintf("Key Pair with name %q cannot be found. A key pair can be added with the resource \"stackit_key_pair\"", name)
diags.AddError(summary, description)
resp.Diagnostics.Append(diags...)

resp.State.RemoveResource(ctx)
return
}
Expand Down