Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions cfn-resources/organization/cmd/resource/config.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

42 changes: 30 additions & 12 deletions cfn-resources/organization/cmd/resource/resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,33 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
return handleError(response, constants.DELETE, err)
}

currentModel.IsDeleted = util.Pointer(false)

responseMsg, progressEvent := runDelete(ctx, conn, currentModel)
if responseMsg.Error != nil {
// Retry once on transient server error, waiting 20 seconds before retrying request
// This covers case of contract tests which create and delete an org within seconds, encountering an error while deleting the org
Comment thread
AgustinBettati marked this conversation as resolved.
if responseMsg.Response != nil && responseMsg.Response.StatusCode == http.StatusInternalServerError {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May want to add a log here

_, _ = logger.Warnf("Transient server error while deleting organization, retrying in 20 seconds")
time.Sleep(20 * time.Second)
responseMsg, progressEvent = runDelete(ctx, conn, currentModel)
}
}
if progressEvent != nil {
return *progressEvent, nil
}
if responseMsg.Error != nil {
return handleError(responseMsg.Response, constants.DELETE, responseMsg.Error)
}

return handler.ProgressEvent{
OperationStatus: handler.Success,
Message: DeleteCompleted,
ResourceModel: nil}, nil
}

// Encapsulate the delete+wait logic so the same flow can be used on retry.
Comment thread
AgustinBettati marked this conversation as resolved.
func runDelete(ctx context.Context, conn *admin.APIClient, currentModel *Model) (*DeleteResponse, *handler.ProgressEvent) {
deleteRequest := conn.OrganizationsApi.DeleteOrg(ctx, *currentModel.OrgId)

// Since the Delete API is synchronous and takes more than 1 minute most of the time,
Expand All @@ -234,31 +261,22 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
responseChan <- DeleteResponse{Error: err, Response: response}
}()

currentModel.IsDeleted = util.Pointer(false)
select {
case responseMsg := <-responseChan:
if responseMsg.Error != nil {
return handleError(responseMsg.Response, constants.DELETE, responseMsg.Error)
}

return &responseMsg, nil
case <-time.After(30 * time.Second):
// If the Delete is not completed in the above time,
// we return a progress event with inProgress status and callback context
return handler.ProgressEvent{
return nil, &handler.ProgressEvent{
OperationStatus: handler.InProgress,
Message: DeleteInProgress,
ResourceModel: currentModel,
CallbackDelaySeconds: CallBackSeconds,
CallbackContext: map[string]interface{}{
constants.StateName: DeletingState,
},
}, nil
}
}

return handler.ProgressEvent{
OperationStatus: handler.Success,
Message: DeleteCompleted,
ResourceModel: nil}, nil
}

func deleteCallback(ctx context.Context, conn *admin.APIClient, currentModel *Model) (handler.ProgressEvent, error) {
Expand Down
Loading