fix(STACKITTPR-168): improve error messages (#762)

* remove deprecated argus resources

* improve error messages
This commit is contained in:
Marcel Jacek 2025-04-04 14:18:16 +02:00 committed by GitHub
parent 1c02c5eb67
commit d6749b6ce3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
76 changed files with 600 additions and 8403 deletions

View file

@ -10,11 +10,11 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/core"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/utils"
"github.com/stackitcloud/terraform-provider-stackit/stackit/internal/validate"
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/stackitcloud/stackit-sdk-go/core/config"
"github.com/stackitcloud/stackit-sdk-go/core/oapierror"
"github.com/stackitcloud/stackit-sdk-go/services/opensearch"
)
@ -241,11 +241,18 @@ func (r *instanceDataSource) Read(ctx context.Context, req datasource.ReadReques
instanceResp, err := r.client.GetInstance(ctx, projectId, instanceId).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
if ok && (oapiErr.StatusCode == http.StatusNotFound || oapiErr.StatusCode == http.StatusGone) {
resp.State.RemoveResource(ctx)
}
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading instance", fmt.Sprintf("Calling API: %v", err))
utils.LogError(
ctx,
&resp.Diagnostics,
err,
"Reading instance",
fmt.Sprintf("Instance with ID %q does not exist in project %q.", instanceId, projectId),
map[int]string{
http.StatusForbidden: fmt.Sprintf("Project with ID %q not found or forbidden access", projectId),
http.StatusGone: fmt.Sprintf("Instance %q is gone.", instanceId),
},
)
resp.State.RemoveResource(ctx)
return
}