private static async Task <DeploymentGetResult> CreateStorageAccountARM(string subscriptionId, string resourceGroupName, object parameters) { var deployment = new AscDeployment { Template = File.ReadAllText(HttpContext.Current.Server.MapPath("~/json/storage-account.json")), DeploymentName = "SVC-CAT-" + DateTime.Now.ToString("hh.mm.ss"), SubscriptionId = subscriptionId, ResourceGroupName = resourceGroupName, Parameters = JsonConvert.SerializeObject(parameters) }; var result = await DeploymentManager.Deploy(deployment); var deploymentResult = await GetDeploymentResultWithPolling(deployment); return(deploymentResult); }
public static async Task <DeploymentValidateResponse> ValidateDeployment(AscDeployment deployment) { var client = Utils.GetResourceManagementClient(deployment.SubscriptionId); Deployment d = new Deployment { Properties = new DeploymentProperties { Mode = DeploymentMode.Incremental, Template = deployment.Template, Parameters = deployment.Parameters } }; var result = await client.Deployments.ValidateAsync(deployment.ResourceGroupName, deployment.DeploymentName, parameters : d, cancellationToken : new CancellationToken()); return(result); }
public static async Task <DeploymentGetResult> GetDeploymentResultWithPolling(AscDeployment deployment, int pollInterval = 3000) { var isRunning = true; DeploymentGetResult deploymentResult = null; while (isRunning) { deploymentResult = await DeploymentManager.GetDeployment(deployment.ResourceGroupName, deployment.DeploymentName, deployment.SubscriptionId); switch (deploymentResult.Deployment.Properties.ProvisioningState) { case "Accepted": case "Running": Thread.Sleep(pollInterval); break; case "Failed": case "Succeeded": isRunning = false; break; } } if (deploymentResult.Deployment.Properties.ProvisioningState == "Failed") { throw new ApplicationException("Error deploying Azure Resource. " + "RequestId: " + deploymentResult.RequestId + ", " + "Id: " + deploymentResult.Deployment.Id + ", " + "CorrelationId: " + deploymentResult.Deployment.Properties.CorrelationId); } return(deploymentResult); }