From 73161821472996a86524a8dc56c26c35e0516f5e Mon Sep 17 00:00:00 2001 From: erikzaadi Date: Sun, 19 May 2024 09:47:25 +0300 Subject: [PATCH] Remove resources from state when page is removed --- port/action-permissions/resource.go | 9 ++++----- port/blueprint-permissions/resource.go | 9 ++++----- port/page-permissions/resource.go | 10 +++++----- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/port/action-permissions/resource.go b/port/action-permissions/resource.go index 6e829e91..a6f63ad7 100644 --- a/port/action-permissions/resource.go +++ b/port/action-permissions/resource.go @@ -54,15 +54,14 @@ func (r *ActionPermissionsResource) Read(ctx context.Context, req resource.ReadR a, statusCode, err := r.portClient.GetActionPermissions(ctx, actionIdentifier) if err != nil { + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError("failed to read action permissions", err.Error()) return } - if statusCode == 404 { - resp.State.RemoveResource(ctx) - return - } - err = refreshActionPermissionsState(ctx, state, a, actionIdentifier) if err != nil { resp.Diagnostics.AddError("failed to refresh action permissions state", err.Error()) diff --git a/port/blueprint-permissions/resource.go b/port/blueprint-permissions/resource.go index 39c0d5ef..97709900 100644 --- a/port/blueprint-permissions/resource.go +++ b/port/blueprint-permissions/resource.go @@ -55,15 +55,14 @@ func (r *BlueprintPermissionsResource) Read(ctx context.Context, req resource.Re a, statusCode, err := r.portClient.GetBlueprintPermissions(ctx, blueprintIdentifier) if err != nil { + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } resp.Diagnostics.AddError("failed to read blueprint permissions", err.Error()) return } - if statusCode == 404 { - resp.State.RemoveResource(ctx) - return - } - err = refreshBlueprintPermissionsState(state, a, blueprintIdentifier) if err != nil { resp.Diagnostics.AddError("failed to refresh blueprint permissions state", err.Error()) diff --git a/port/page-permissions/resource.go b/port/page-permissions/resource.go index a44fc7f9..0cd04ba9 100644 --- a/port/page-permissions/resource.go +++ b/port/page-permissions/resource.go @@ -54,12 +54,12 @@ func (r *PagePermissionsResource) Read(ctx context.Context, req resource.ReadReq a, statusCode, err := r.portClient.GetPagePermissions(ctx, pageIdentifier) if err != nil { - resp.Diagnostics.AddError("failed to read page permissions", err.Error()) - return - } + if statusCode == 404 { + resp.State.RemoveResource(ctx) + return + } - if statusCode == 404 { - resp.State.RemoveResource(ctx) + resp.Diagnostics.AddError("failed to read page permissions", err.Error()) return }