Skip to content

Commit 68c4047

Browse files
committed
fixup
Signed-off-by: Alexander Dahmen <alexander.dahmen@inovex.de>
1 parent c57c8f7 commit 68c4047

File tree

1 file changed

+14
-2
lines changed
  • stackit/internal/services/objectstorage/compliance-lock

1 file changed

+14
-2
lines changed

stackit/internal/services/objectstorage/compliance-lock/resource.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package compliancelock
22

33
import (
44
"context"
5+
"errors"
56
"fmt"
67
"net/http"
78

@@ -164,8 +165,19 @@ func (r *compliancelockResource) Create(ctx context.Context, req resource.Create
164165

165166
complianceResp, err := r.client.CreateComplianceLock(ctx, projectId, region).Execute()
166167
if err != nil {
167-
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating compliance lock", fmt.Sprintf("Calling API: %v", err))
168-
return
168+
var oapiErr *oapierror.GenericOpenAPIError
169+
ok := errors.As(err, &oapiErr)
170+
if ok && oapiErr.StatusCode == http.StatusConflict {
171+
tflog.Info(ctx, "Compliance lock is already enabled for this project. Please check duplicate resources.")
172+
complianceResp, err = r.client.GetComplianceLock(ctx, projectId, region).Execute()
173+
if err != nil {
174+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error reading compliance lock", fmt.Sprintf("Calling API: %v", err))
175+
return
176+
}
177+
} else {
178+
core.LogAndAddError(ctx, &resp.Diagnostics, "Error creating compliance lock", fmt.Sprintf("Calling API: %v", err))
179+
return
180+
}
169181
}
170182

171183
// Map response body to schema

0 commit comments

Comments
 (0)