protected async Task InitializeResourceGroupSelectionAsync( CancellationToken cancellationToken = default ) { // Select existing ResourceGroup or create a new one. if (_configurationProvider.IfUseExistingResourceGroup()) { var resourceGroups = _azureResourceManager.GetResourceGroups(); _resourceGroup = _configurationProvider.GetExistingResourceGroup(resourceGroups); } else { bool ifResourceGroupExists(string _resourceGroupName) { var _resourceGroupExists = _azureResourceManager .CheckIfResourceGroupExistsAsync( _resourceGroupName, cancellationToken ) .Result; return(_resourceGroupExists); } var defaultResourceGroupName = ifResourceGroupExists(_applicationName) ? null : _applicationName; var newRGParams = _configurationProvider.GetNewResourceGroup( AzureResourceManager.FunctionalRegions, ifResourceGroupExists, defaultResourceGroupName ); _resourceGroup = await _azureResourceManager .CreateResourceGroupAsync( newRGParams.Item1, newRGParams.Item2, _defaultTagsDict, cancellationToken ); } }
public async Task InitializeResourceGroupSelectionAsync( CancellationToken cancellationToken = default ) { _azureResourceManager = new AzureResourceManager(_azureCredentials); // Select subscription to use. var subscriptionsList = _azureResourceManager.GetSubscriptions(); _subscription = _configurationProvider.SelectSubscription(subscriptionsList); _azureResourceManager.Init(_subscription); // Select existing ResourceGroup or create a new one. var useExisting = _configurationProvider.CheckIfUseExistingResourceGroup(); if (useExisting) { var resourceGroups = _azureResourceManager.GetResourceGroups(); _resourceGroup = _configurationProvider.SelectExistingResourceGroup(resourceGroups); } else { var region = _configurationProvider .SelectResourceGroupRegion( AzureResourceManager.FunctionalRegions ); bool checkIfResourceGroupExists(string _resourceGroupName) { var _resourceGroupExists = _azureResourceManager .CheckIfResourceGroupExistsAsync( _resourceGroupName, cancellationToken ) .Result; return(_resourceGroupExists); } string defaultResourceGroupName = null; if (!checkIfResourceGroupExists(_applicationName)) { defaultResourceGroupName = _applicationName; } var newResourceGroupName = _configurationProvider .SelectResourceGroupName( checkIfResourceGroupExists, defaultResourceGroupName ); _resourceGroup = await _azureResourceManager .CreateResourceGroupAsync( region, newResourceGroupName, _defaultTagsDict, cancellationToken ); } }