in aws-aps-workspace/cmd/resource/resource.go [32:84]
func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler.ProgressEvent, error) {
if currentModel.WorkspaceId != nil && len(req.CallbackContext) == 0 {
return handler.ProgressEvent{
OperationStatus: handler.Failed,
Message: "Invalid Create: cannot create a resource using readOnly workspaceId property",
HandlerErrorCode: cloudformation.HandlerErrorCodeInvalidRequest,
}, nil
}
client := internal.NewAPS(req.Session)
// wait for workspace to be ACTIVE before managing alert manager configuration
if arn, ok := req.CallbackContext[waitForWorkspaceStatusKey]; ok {
currentModel.Arn = aws.String(arn.(string))
evt, err := validateWorkspaceState(
client,
currentModel,
prometheusservice.WorkspaceStatusCodeActive,
messageCreateComplete)
if evt.OperationStatus == handler.InProgress || currentModel.AlertManagerDefinition == nil {
return evt, err
}
return createAlertManagerDefinition(req, client, currentModel)
}
// AlertManagerDefinition is always created last. As such we have to continue waiting after the Workspace is created
if arn, ok := req.CallbackContext[waitForAlertManagerStatusActiveKey]; ok {
currentModel.Arn = aws.String(arn.(string))
return validateAlertManagerState(client,
currentModel,
prometheusservice.AlertManagerDefinitionStatusCodeActive,
messageCreateComplete)
}
resp, err := client.CreateWorkspace(&prometheusservice.CreateWorkspaceInput{
Alias: currentModel.Alias,
Tags: tagsToStringMap(currentModel.Tags),
})
if err != nil {
return internal.NewFailedEvent(err)
}
currentModel.Arn = resp.Arn
return handler.ProgressEvent{
OperationStatus: handler.InProgress,
Message: messageInProgress,
ResourceModel: currentModel,
CallbackDelaySeconds: defaultCallbackSeconds,
CallbackContext: buildWaitForWorkspaceStatusCallbackContext(currentModel),
}, nil
}