diff --git a/source/Calamari.Azure/Deployment/Conventions/AzureWebAppConvention.cs b/source/Calamari.Azure/Deployment/Conventions/AzureWebAppConvention.cs index 530e854b7..3476158c5 100644 --- a/source/Calamari.Azure/Deployment/Conventions/AzureWebAppConvention.cs +++ b/source/Calamari.Azure/Deployment/Conventions/AzureWebAppConvention.cs @@ -1,6 +1,5 @@ using System; using System.Diagnostics; -using System.IO; using System.Threading; using Calamari.Azure.Integration.Websites.Publishing; using Calamari.Commands.Support; @@ -18,9 +17,13 @@ public void Install(RunningDeployment deployment) { var variables = deployment.Variables; var subscriptionId = variables.Get(SpecialVariables.Action.Azure.SubscriptionId); + var resourceGroupName = variables.Get(SpecialVariables.Action.Azure.ResourceGroupName, string.Empty); var siteName = variables.Get(SpecialVariables.Action.Azure.WebAppName); - Log.Info("Deploying to Azure WebApp '{0}' using subscription-id '{1}'", siteName, subscriptionId); + Log.Info("Deploying to Azure WebApp '{0}'{1}, using subscription-id '{2}'", + siteName, + string.IsNullOrEmpty(resourceGroupName) ? string.Empty : $" in Resource Group {resourceGroupName}", + subscriptionId); var publishProfile = GetPublishProfile(variables); @@ -71,7 +74,9 @@ private static SitePublishProfile GetPublishProfile(VariableDictionary variables switch (accountType) { case AzureAccountTypes.ServicePrincipalAccountType: - return ResourceManagerPublishProfileProvider.GetPublishProperties(subscriptionId, siteName, + return ResourceManagerPublishProfileProvider.GetPublishProperties(subscriptionId, + variables.Get(SpecialVariables.Action.Azure.ResourceGroupName, string.Empty), + siteName, variables.Get(SpecialVariables.Action.Azure.TenantId), variables.Get(SpecialVariables.Action.Azure.ClientId), variables.Get(SpecialVariables.Action.Azure.Password)); diff --git a/source/Calamari.Azure/Integration/Websites/Publishing/ResourceManagerPublishProfileProvider.cs b/source/Calamari.Azure/Integration/Websites/Publishing/ResourceManagerPublishProfileProvider.cs index 414228f4d..6b695bb0b 100644 --- a/source/Calamari.Azure/Integration/Websites/Publishing/ResourceManagerPublishProfileProvider.cs +++ b/source/Calamari.Azure/Integration/Websites/Publishing/ResourceManagerPublishProfileProvider.cs @@ -16,7 +16,7 @@ namespace Calamari.Azure.Integration.Websites.Publishing { public class ResourceManagerPublishProfileProvider { - public static SitePublishProfile GetPublishProperties(string subscriptionId, string siteName, string tenantId, string applicationId, string password) + public static SitePublishProfile GetPublishProperties(string subscriptionId, string resourceGroupName, string siteName, string tenantId, string applicationId, string password) { var token = ServicePrincipal.GetAuthorizationToken(tenantId, applicationId, password); @@ -24,8 +24,9 @@ public static SitePublishProfile GetPublishProperties(string subscriptionId, str using (var resourcesClient = new ResourceManagementClient(new TokenCloudCredentials(subscriptionId, token))) using (var webSiteClient = new WebSiteManagementClient(new TokenCredentials(token)) { SubscriptionId = subscriptionId}) { - // Because we only know the site name, we need to search the ResourceGroups to find it - var resourceGroups = resourcesClient.ResourceGroups.List(new ResourceGroupListParameters()).ResourceGroups.Select(rg => rg.Name).ToList(); + // We may need to search all ResourceGroups, if one isn't specified. New Step template will always provide the Resource Group, it is currently treated as optional here + // for backward compatibility. + var resourceGroups = resourcesClient.ResourceGroups.List(new ResourceGroupListParameters()).ResourceGroups.Where(rg => string.IsNullOrWhiteSpace(resourceGroupName) || string.Equals(rg.Name, resourceGroupName, StringComparison.InvariantCultureIgnoreCase)).Select(rg => rg.Name).ToList(); foreach (var resourceGroup in resourceGroups) {