/// <summary>
        ///
        /// </summary>
        /// <param name="location"></param>
        /// <param name="resourcegroupName"></param>
        /// <param name="workspaceName"></param>
        /// <param name="computeName"></param>
        /// <param name="useGPUCompute"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public async Task <ComputeResource> AttachCompute(string location,
                                                          string resourcegroupName,
                                                          string workspaceName,
                                                          string computeName,
                                                          bool useGPUCompute = true,
                                                          CancellationToken cancellationToken = default)
        {
            if (!WorkspaceManagementHelpers.ValidateComputeName(computeName))
            {
                // Provided Compute name is invalid
                throw new ArgumentException(nameof(computeName));
            }
            try
            {
                return(await this.machineLearningWorkspacesClient.MachineLearningCompute.GetAsync(resourcegroupName, workspaceName, computeName, cancellationToken).ConfigureAwait(false));
            }
            catch (MachineLearningServiceErrorException mlEx)
            {
                if (mlEx.Body.Error.Code == "ResourceNotFound")
                {
                    AmlCompute      computeToAttach = useGPUCompute ? GetAmlComputeConfiguration(location, vmSize: WorkspaceClient.GPUComputeVmSize) : GetAmlComputeConfiguration(location);
                    ComputeResource resource        = new ComputeResource
                    {
                        Properties = computeToAttach,
                        Location   = location
                    };

                    return(await this.machineLearningWorkspacesClient.MachineLearningCompute.CreateOrUpdateAsync(resourcegroupName, workspaceName, computeName, resource, cancellationToken).ConfigureAwait(false));
                }

                throw;
            }
        }
        private async Task <IDeployment> CreateWorkspaceDeploymentAsync(Region region,
                                                                        string workspaceName,
                                                                        Guid subscriptionId,
                                                                        string resourceGroupName,
                                                                        string friendlyName                 = null,
                                                                        bool createResourceGroup            = true,
                                                                        string storageAccountName           = null,
                                                                        string keyVaultName                 = null,
                                                                        string applicationInsightsName      = null,
                                                                        string azureContainerRegistryName   = null,
                                                                        CancellationToken cancellationToken = default)
        {
            if (string.IsNullOrEmpty(storageAccountName))
            {
                storageAccountName = WorkspaceManagementHelpers.GenerateNameForDependentResource(workspaceName, WorkspaceManagementHelpers.DependentResourceType.StorageAccount);
            }

            if (string.IsNullOrEmpty(keyVaultName))
            {
                keyVaultName = WorkspaceManagementHelpers.GenerateNameForDependentResource(workspaceName, WorkspaceManagementHelpers.DependentResourceType.KeyVault);
            }

            if (string.IsNullOrEmpty(applicationInsightsName))
            {
                applicationInsightsName = WorkspaceManagementHelpers.GenerateNameForDependentResource(workspaceName, WorkspaceManagementHelpers.DependentResourceType.ApplicationInsights);
            }

            if (string.IsNullOrEmpty(azureContainerRegistryName))
            {
                azureContainerRegistryName = WorkspaceManagementHelpers.GenerateNameForDependentResource(workspaceName, WorkspaceManagementHelpers.DependentResourceType.ContainerRegistry);
            }

            if (!WorkspaceManagementHelpers.ValidateApplicationInsightName(applicationInsightsName))
            {
                throw new ArgumentException($"Application Insights name name is invalid, does not conform to Azure naming rules.  {applicationInsightsName}");
            }

            if (!WorkspaceManagementHelpers.ValidateAzureDNSName(keyVaultName))
            {
                throw new ArgumentException($"Key Vault name is invalid, does not conform to Azure naming rules.  {keyVaultName}");
            }

            if (!WorkspaceManagementHelpers.ValidateAzureContainerName(azureContainerRegistryName))
            {
                throw new ArgumentException($"Container Registry name is invalid, does not conform to Azure naming rules.  {azureContainerRegistryName}");
            }

            if (!WorkspaceManagementHelpers.ValidateAzureDNSName(storageAccountName))
            {
                throw new ArgumentException($"Storage Account name is invalid, does not conform to Azure naming rules.  {storageAccountName}");
            }

            var template = new ArmTemplateBuilder();
            var workspace_dependencies = new JArray();

            // Build KeyVault
            JObject kvResource = ArmTemplateBuilder.BuildKVTemplate(keyVaultName, region, this.TenantId);

            template.AddResource(kvResource);
            workspace_dependencies.Add($"[resourceId('Microsoft.KeyVault/vaults', '{keyVaultName}')]");

            string kvResourceId = GetArmResourceId(subscriptionId.ToString(), resourceGroupName, "Microsoft.KeyVault/vaults", keyVaultName);

            // Build Storage Account
            JObject storageResource = ArmTemplateBuilder.BuildStorageAccountTemplate(storageAccountName, region);

            template.AddResource(storageResource);

            workspace_dependencies.Add($"[resourceId('Microsoft.Storage/storageAccounts', '{storageAccountName}')]");
            string storageResourceId = GetArmResourceId(subscriptionId.ToString(), resourceGroupName, "Microsoft.Storage/storageAccounts", storageAccountName);

            // Build Azure Container Registry
            JObject acrResource = ArmTemplateBuilder.BuildAzureContainerRegistryTemplate(azureContainerRegistryName, region);

            template.AddResource(acrResource);
            workspace_dependencies.Add($"[resourceId('Microsoft.ContainerRegistry/registries', '{azureContainerRegistryName}')]");
            string acrResourceId = GetArmResourceId(subscriptionId.ToString(), resourceGroupName, "Microsoft.ContainerRegistry/registries", azureContainerRegistryName);

            // Build App Insights Instance
            JObject appInsightsResource = template.BuildApplicationInsightsTemplate(applicationInsightsName, region);

            template.AddResource(appInsightsResource);
            workspace_dependencies.Add($"[resourceId('Microsoft.Insights/components', '{applicationInsightsName}')]");
            string appInsightsResourceId = GetArmResourceId(subscriptionId.ToString(), resourceGroupName, "Microsoft.Insights/components", applicationInsightsName);

            // Build Workspace
            JObject workspaceResource = ArmTemplateBuilder.BuildWorkspaceResource(workspaceName, region, kvResourceId, acrResourceId, storageResourceId, friendlyName, appInsightsResourceId);

            workspaceResource.GetValue("dependsOn").Replace(workspace_dependencies);

            template.AddResource(workspaceResource);

            // See https://github.com/Azure-Samples/resources-dotnet-deploy-using-arm-template

            var azure = Azure.Configure()
                        .WithLogLevel(HttpLoggingDelegatingHandler.Level.Basic)
                        .Authenticate(new AzureCredentials(this.Credentials, this.Credentials, this.TenantId, AzureEnvironment.AzureGlobalCloud))
                        .WithSubscription(subscriptionId.ToString());

            IDeployment deployment;

            if (createResourceGroup)
            {
                deployment = await azure.Deployments.Define(Guid.NewGuid().ToString())
                             .WithNewResourceGroup(resourceGroupName, region)
                             .WithTemplate(template.GetTemplate().ToString())
                             .WithParameters("{}")
                             .WithMode(DeploymentMode.Incremental)
                             .CreateAsync(cancellationToken).ConfigureAwait(false);
            }
            else
            {
                deployment = await azure.Deployments.Define(Guid.NewGuid().ToString())
                             .WithExistingResourceGroup(resourceGroupName)
                             .WithTemplate(template.GetTemplate().ToString())
                             .WithParameters("{}")
                             .WithMode(DeploymentMode.Incremental)
                             .CreateAsync(cancellationToken).ConfigureAwait(false);
            }

            return(deployment);
        }