Skip to content

Commit

Permalink
addressed some PR comments
Browse files Browse the repository at this point in the history
  • Loading branch information
rauchy committed Oct 16, 2024
1 parent 81769af commit 2efc446
Showing 1 changed file with 16 additions and 17 deletions.
33 changes: 16 additions & 17 deletions internal/providers/pluginfw/resources/sharing/resource_share.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ func diff(beforeSi sharing.ShareInfo, afterSi sharing.ShareInfo) []sharing.Share
changes := []sharing.SharedDataObjectUpdate{}
// not in after so remove
for _, beforeSdo := range beforeSi.Objects {
_, exists := afterMap[beforeSdo.Name]
if exists {
if _, ok := afterMap[beforeSdo.Name]; ok {
continue
}
changes = append(changes, sharing.SharedDataObjectUpdate{
Expand All @@ -94,8 +93,7 @@ func diff(beforeSi sharing.ShareInfo, afterSi sharing.ShareInfo) []sharing.Share
// not in before so add
// if in before but diff then update
for _, afterSdo := range afterSi.Objects {
beforeSdo, exists := beforeMap[afterSdo.Name]
if exists {
if beforeSdo, ok := beforeMap[afterSdo.Name]; ok {
if !equal(beforeSdo, afterSdo) {
// do not send SharedAs
afterSdo.SharedAs = ""
Expand Down Expand Up @@ -344,26 +342,27 @@ func (r *ShareResource) Update(ctx context.Context, req resource.UpdateRequest,
Name: plan.Name.ValueString(),
Updates: changes,
})
if err == nil {
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, updatedShareInfo, &state)...)
if resp.Diagnostics.HasError() {
return
}
} else {

if err != nil {
resp.Diagnostics.AddError("failed to update share", err.Error())

rollbackShareInfo, rollbackErr := client.Shares.Update(ctx, sharing.UpdateShare{
Name: currentShareInfo.Name,
Owner: currentShareInfo.Owner,
})
if rollbackErr == nil {
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, rollbackShareInfo, &state)...)
if resp.Diagnostics.HasError() {
return
}
} else {
if rollbackErr != nil {
resp.Diagnostics.AddError("failed to roll back", common.OwnerRollbackError(err, rollbackErr, currentShareInfo.Owner, plan.Owner.ValueString()).Error())
return
}

resp.Diagnostics.AddError("failed to update share", err.Error())
resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, rollbackShareInfo, &state)...)
if resp.Diagnostics.HasError() {
return
}
}

resp.Diagnostics.Append(converters.GoSdkToTfSdkStruct(ctx, updatedShareInfo, &state)...)
if resp.Diagnostics.HasError() {
return
}
}
Expand Down

0 comments on commit 2efc446

Please sign in to comment.