Skip to content

Commit

Permalink
add some diagnostics checks
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchy committed Oct 15, 2024
1 parent 87c5241 commit 37824e8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/providers/pluginfw/resources/sharing/resource_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,9 @@ func (r *ShareResource) Create(ctx context.Context, req resource.CreateRequest,
}

resp.Diagnostics.Append(resp.State.Set(ctx, newState)...)
if resp.Diagnostics.HasError() {
return
}
}

func (r *ShareResource) Read(ctx context.Context, req resource.ReadRequest, resp *resource.ReadResponse) {
Expand Down Expand Up @@ -251,9 +254,6 @@ func (r *ShareResource) Read(ctx context.Context, req resource.ReadRequest, resp
}

shareInfo, err := w.Shares.Get(ctx, getShareRequest)
matchOrder(shareInfo.Objects, stateGoSDK.Objects, func(obj sharing.SharedDataObject) string { return obj.Name })
suppressCDFEnabledDiff(shareInfo)

if err != nil {
if apierr.IsMissing(err) {
resp.State.RemoveResource(ctx)
Expand All @@ -263,6 +263,9 @@ func (r *ShareResource) Read(ctx context.Context, req resource.ReadRequest, resp
return
}

matchOrder(shareInfo.Objects, stateGoSDK.Objects, func(obj sharing.SharedDataObject) string { return obj.Name })
suppressCDFEnabledDiff(shareInfo)

var newState ShareInfoExtended
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, shareInfo, &newState)...)
if resp.Diagnostics.HasError() {
Expand Down Expand Up @@ -308,6 +311,7 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,

currentShareInfo, err := client.Shares.Get(ctx, getShareRequest)
if err != nil {
resp.Diagnostics.AddError("failed to get current share info", err.Error())
return
}

Expand All @@ -328,7 +332,7 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,
return
}
} else {
resp.Diagnostics.AddError("failed to share owner", err.Error())
resp.Diagnostics.AddError("failed to update share owner", err.Error())
return
}
}
Expand Down Expand Up @@ -359,6 +363,7 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,
}

resp.Diagnostics.AddError("failed to update share", err.Error())
return
}
}

Expand All @@ -385,5 +390,6 @@ func (r *ShareResource) Delete(ctx context.Context, req resource.DeleteRequest,
err := w.Shares.DeleteByName(ctx, deleteShareRequest.Name.ValueString())
if err != nil && !apierr.IsMissing(err) {
resp.Diagnostics.AddError("failed to delete share", err.Error())
return
}
}

0 comments on commit 37824e8

Please sign in to comment.