public async Task CreateDeployments() { #region Snippet:Managing_Deployments_CreateADeployment // First we need to get the deployment collection from the resource group DeploymentCollection deploymentCollection = resourceGroup.GetDeployments(); // Use the same location as the resource group string deploymentName = "myDeployment"; var input = new DeploymentInput(new DeploymentProperties(DeploymentMode.Incremental) { TemplateLink = new TemplateLink() { Uri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.storage/storage-account-create/azuredeploy.json" }, Parameters = new JsonObject() { { "storageAccountType", new JsonObject() { { "value", "Standard_GRS" } } } } }); DeploymentCreateOrUpdateOperation lro = await deploymentCollection.CreateOrUpdateAsync(true, deploymentName, input); Deployment deployment = lro.Value; #endregion Snippet:Managing_Deployments_CreateADeployment }
public async Task CreateDeploymentsUsingJsonElement() { #region Snippet:Managing_Deployments_CreateADeploymentUsingJsonElement // First we need to get the deployment collection from the resource group DeploymentCollection deploymentCollection = resourceGroup.GetDeployments(); // Use the same location as the resource group string deploymentName = "myDeployment"; // Create a parameter object var parametersObject = new { storageAccountType = new { value = "Standard_GRS" } }; //convert this object to JsonElement var parametersString = JsonSerializer.Serialize(parametersObject); var parameters = JsonDocument.Parse(parametersString).RootElement; var input = new DeploymentInput(new DeploymentProperties(DeploymentMode.Incremental) { TemplateLink = new TemplateLink() { Uri = "https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/quickstarts/microsoft.storage/storage-account-create/azuredeploy.json" }, Parameters = parameters }); DeploymentCreateOrUpdateOperation lro = await deploymentCollection.CreateOrUpdateAsync(true, deploymentName, input); Deployment deployment = lro.Value; #endregion Snippet:Managing_Deployments_CreateADeployment }
public async virtual Task <DeploymentCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string deploymentName, DeploymentInput parameters, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(deploymentName, nameof(deploymentName)); if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _deploymentClientDiagnostics.CreateScope("DeploymentCollection.CreateOrUpdate"); scope.Start(); try { var response = await _deploymentRestClient.CreateOrUpdateAtScopeAsync(Id, deploymentName, parameters, cancellationToken).ConfigureAwait(false); var operation = new DeploymentCreateOrUpdateOperation(ArmClient, _deploymentClientDiagnostics, Pipeline, _deploymentRestClient.CreateCreateOrUpdateAtScopeRequest(Id, deploymentName, parameters).Request, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async Task CreateDeploymentsUsingString() { #region Snippet:Managing_Deployments_CreateADeploymentUsingString // First we need to get the deployment collection from the resource group DeploymentCollection deploymentCollection = resourceGroup.GetDeployments(); // Use the same location as the resource group string deploymentName = "myDeployment"; // Passing string to template and parameters var input = new DeploymentInput(new DeploymentProperties(DeploymentMode.Incremental) { Template = File.ReadAllText("storage-template.json"), Parameters = File.ReadAllText("storage-parameters.json") }); DeploymentCreateOrUpdateOperation lro = await deploymentCollection.CreateOrUpdateAsync(true, deploymentName, input); Deployment deployment = lro.Value; #endregion Snippet:Managing_Deployments_CreateADeployment }
private static string GetDeploymentResultMessage(DeploymentCreateOrUpdateOperation deploymentCreateOrUpdateOperation) { if (!deploymentCreateOrUpdateOperation.HasValue) { return(LangServerResources.DeploymentFailedMessage); } var response = deploymentCreateOrUpdateOperation.GetRawResponse(); var status = response.Status; if (status == 200 || status == 201) { return(LangServerResources.DeploymentSucceededMessage); } else { return(string.Format(LangServerResources.DeploymentFailedWithExceptionMessage, response.ToString())); } }