in cfn-resources/cluster/cmd/resource/resource.go [521:567]
func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {
setup()
log.Debugf("Delete() currentModel:%+v", currentModel)
client, err := util.CreateMongoDBClient(*currentModel.ApiKeys.PublicKey, *currentModel.ApiKeys.PrivateKey)
if err != nil {
log.Infof("Delete err: %+v", err)
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: err.Error(),
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest}, nil
}
if _, ok := req.CallbackContext["stateName"]; ok {
return validateProgress(client, req, currentModel, "DELETED", "DELETING")
}
projectID := *currentModel.ProjectId
clusterName := *currentModel.Name
resp, err := client.Clusters.Delete(context.Background(), projectID, clusterName)
if err != nil {
if resp != nil && resp.StatusCode == 404 {
log.Infof("Delete 404 err: %+v", err)
return handler.ProgressEvent{
Message: err.Error(),
OperationStatus: handler.Failed,
HandlerErrorCode: cloudformation.HandlerErrorCodeNotFound}, nil
} else {
log.Infof("Delete err: %+v", err)
return handler.ProgressEvent{
Message: err.Error(),
OperationStatus: handler.Failed,
HandlerErrorCode: cloudformation.HandlerErrorCodeServiceInternalError}, nil
}
}
mm := fmt.Sprintf("%s-Deleting", projectID)
currentModel.Id = &mm
return handler.ProgressEvent{
OperationStatus: handler.InProgress,
Message: "Delete Complete",
ResourceModel: currentModel,
CallbackDelaySeconds: 65,
CallbackContext: map[string]interface{}{
"stateName": "DELETING",
},
}, nil
}