/// <summary> /// The operation to create or update a resource group. Please note some properties can be set only during creation. /// </summary> /// <param name="name"> The name of the resource group. </param> /// <param name="resourceDetails"> The desired resource group configuration. </param> /// <param name="waitForCompletion"> Waits for the completion of the long running operations. </param> /// <param name="cancellationToken"> A token to allow the caller to cancel the call to the service. The default value is <see cref="CancellationToken.None" />. </param> /// <returns> A <see cref="Task"/> that on completion returns a response with the <see cref="Response{ResourceGroup}"/> operation for this resource group. </returns> /// <exception cref="ArgumentException"> Name of the resource group cannot be null or a whitespace. </exception> /// <exception cref="ArgumentNullException"> resourceDetails cannot be null. </exception> public virtual async Task <ResourceGroupCreateOrUpdateOperation> CreateOrUpdateAsync(string name, ResourceGroupData resourceDetails, bool waitForCompletion = true, CancellationToken cancellationToken = default) { if (string.IsNullOrWhiteSpace(name)) { throw new ArgumentException("name cannot be null or a whitespace.", nameof(name)); } if (resourceDetails is null) { throw new ArgumentNullException(nameof(resourceDetails)); } using var scope = Diagnostics.CreateScope("ResourceGroupCollection.CreateOrUpdate"); scope.Start(); try { var originalResponse = await RestClient.CreateOrUpdateAsync(name, resourceDetails, cancellationToken).ConfigureAwait(false); var operation = new ResourceGroupCreateOrUpdateOperation(Parent, originalResponse); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }
public async virtual Task <ResourceGroupCreateOrUpdateOperation> CreateOrUpdateAsync(bool waitForCompletion, string resourceGroupName, ResourceGroupData parameters, CancellationToken cancellationToken = default) { Argument.AssertNotNullOrEmpty(resourceGroupName, nameof(resourceGroupName)); if (parameters == null) { throw new ArgumentNullException(nameof(parameters)); } using var scope = _resourceGroupClientDiagnostics.CreateScope("ResourceGroupCollection.CreateOrUpdate"); scope.Start(); try { var response = await _resourceGroupRestClient.CreateOrUpdateAsync(Id.SubscriptionId, resourceGroupName, parameters, cancellationToken).ConfigureAwait(false); var operation = new ResourceGroupCreateOrUpdateOperation(ArmClient, response); if (waitForCompletion) { await operation.WaitForCompletionAsync(cancellationToken).ConfigureAwait(false); } return(operation); } catch (Exception e) { scope.Failed(e); throw; } }