public Task <YJsonResult <YResource> > CreateWorkspaceAsync(Guid engineId, [FromBody] YDataBricksPayload payload)
 {
     return(YExecuteAsync(async() =>
     {
         var response = await this.client.ProcessRequestApiAsync <YResource>($"api/DataBricks/{engineId}", null, payload, HttpMethod.Put).ConfigureAwait(false);
         return response.Value;
     }));
 }
        public async Task <ActionResult <YResource> > CreateDataBricksWorkspaceAsync(Guid engineId, [FromBody] YDataBricksPayload payload)
        {
            payload.Location.EnsureLocation();

            var engine = await this.engineProvider.GetEngineAsync(engineId).ConfigureAwait(false);

            if (engine == null)
            {
                throw new Exception("Engine does not exists");
            }

            var resourceGroupName = engine.ResourceGroupName;
            var workspaceName     = engine.ClusterName;


            var managedResourceGroupId = string.IsNullOrEmpty(payload.ManagedResourceGroupId) ? $"dataBricks-{resourceGroupName}" : payload.ManagedResourceGroupId;

            if (managedResourceGroupId == resourceGroupName)
            {
                throw new Exception($"The managed resource group can not have the same name as resource group name");
            }

            // Create Databricks payload
            var resourceRequest = new YResource
            {
                Location   = payload.Location,
                Properties = new Dictionary <string, object>()
                {
                    { "managedResourceGroupId", $"/subscriptions/{this.options.SubscriptionId}/resourceGroups/{managedResourceGroupId}" }
                }
            };

            var resourceResponse = await this.resourceClient.StartCreateOrUpdateAsync
                                       (resourceGroupName, "Microsoft.Databricks", "", "workspaces", workspaceName, DataBricksApiVersion, resourceRequest);

            var provisioningState = resourceResponse.Value.Properties["provisioningState"].ToString();

            if (provisioningState == "Accepted" || provisioningState == "Succeeded")
            {
                engine = await this.engineProvider.GetEngineAsync(payload.EngineId);

                await this.engineProvider.SaveEngineAsync(engine);
            }

            return(resourceResponse.Value);
        }