Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[AppService]: Feature #19496 Added -Tag parameter support to New-AzWebApp & New-AzWebAppSlot #20019

Merged
merged 8 commits into from
Nov 8, 2022
5 changes: 4 additions & 1 deletion src/Websites/Websites.Test/ScenarioTests/WebAppSlotTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ function Test-CreateNewWebAppSlot
$planName = Get-WebHostPlanName
$tier = "Standard"
$resourceType = "Microsoft.Web/sites"
$tag= @{"TagKey" = "TagValue"}
try
{
#Setup
Expand All @@ -318,7 +319,7 @@ function Test-CreateNewWebAppSlot
Assert-AreEqual $serverFarm.Id $result.ServerFarmId

# Create deployment slot
$job = New-AzWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -AsJob
$job = New-AzWebAppSlot -ResourceGroupName $rgname -Name $appname -Slot $slotname -Tag $tag -AsJob
$job | Wait-Job
$slot1 = $job | Receive-Job

Expand All @@ -327,6 +328,8 @@ function Test-CreateNewWebAppSlot
# Assert
Assert-AreEqual $appWithSlotName $slot1.Name
Assert-AreEqual $serverFarm.Id $slot1.ServerFarmId
Assert-AreEqual $tag.Keys $slot1.Tags.Keys
Assert-AreEqual $tag.Values $slot1.Tags.Values
}
finally
{
Expand Down
7 changes: 5 additions & 2 deletions src/Websites/Websites.Test/ScenarioTests/WebAppTests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -422,20 +422,23 @@ function Test-CreateNewWebApp
$tier = "Shared"
$apiversion = "2015-08-01"
$resourceType = "Microsoft.Web/sites"
$tag= @{"TagKey" = "TagValue"}
try
{
#Setup
New-AzResourceGroup -Name $rgname -Location $location
$serverFarm = New-AzAppServicePlan -ResourceGroupName $rgname -Name $whpName -Location $location -Tier $tier

# Create new web app
$job = New-AzWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName -AsJob
$job = New-AzWebApp -ResourceGroupName $rgname -Name $wname -Location $location -AppServicePlan $whpName -Tag $tag -AsJob
$job | Wait-Job
$actual = $job | Receive-Job

# Assert
Assert-AreEqual $wname $actual.Name
Assert-AreEqual $serverFarm.Id $actual.ServerFarmId
Assert-AreEqual $tag.Keys $actual.Tags.Keys
Assert-AreEqual $tag.Values $actual.Tags.Values

# Get new web app
$result = Get-AzWebApp -ResourceGroupName $rgname -Name $wname
Expand Down Expand Up @@ -1589,4 +1592,4 @@ function Test-TagsNotRemovedBySetWebApp
$asp = Get-AzAppServicePlan -ResourceGroupName $rgname -Name $aspName
Assert-AreEqual $webApp.ServerFarmId $asp.id
Assert-notNull $webApp.Tags
}
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/Websites/Websites/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
- Additional information about change #1
-->
## Upcoming Release

* Added Tag parameter for `New-AzWebApp` and `New-AzWebAppSlot`
Kotasudhakarreddy marked this conversation as resolved.
Show resolved Hide resolved
## Version 2.11.5
* Fixed `Publish-AzWebApp` to use latest publish API when deploying war package [#19791]
## Version 2.11.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public class NewAzureWebAppSlotCmdlet : WebAppBaseClientCmdLet
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }
Kotasudhakarreddy marked this conversation as resolved.
Show resolved Hide resolved

[Parameter(Mandatory = false, HelpMessage = "Tags are name/value pairs that enable you to categorize resources")]
public Hashtable Tag { get; set; }

private Hashtable GetAppSettingsToUpdate()
{
Hashtable appSettings = new Hashtable();
Expand Down Expand Up @@ -181,7 +184,7 @@ public override void ExecuteCmdlet()
}

var webApp = new PSSite(WebsitesClient.GetWebApp(ResourceGroupName, Name, null));
var site = new PSSite(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan==null?webApp.ServerFarmId : AppServicePlan, cloningInfo, AseName, AseResourceGroupName));
var site = new PSSite(WebsitesClient.CreateWebApp(ResourceGroupName, Name, Slot, webApp.Location, AppServicePlan==null?webApp.ServerFarmId : AppServicePlan, cloningInfo, AseName, AseResourceGroupName, (IDictionary<string, string>)CmdletHelpers.ConvertToStringDictionary(Tag)));
UpdateConfigIfNeeded(site);
Kotasudhakarreddy marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down
6 changes: 5 additions & 1 deletion src/Websites/Websites/Cmdlets/WebApps/NewAzureWebApp.cs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,9 @@ public class NewAzureWebAppCmdlet : WebAppBaseClientCmdLet
[Parameter(Mandatory = false, HelpMessage = "Path to the GitHub repository containign the web application to deploy.", ParameterSetName = SimpleParameterSet)]
public string GitRepositoryPath { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Tags are name/value pairs that enable you to categorize resources", ParameterSetName = SimpleParameterSet)]
public Hashtable Tag { get; set; }

protected override void ProcessRecord()
{
try
Expand Down Expand Up @@ -386,7 +389,8 @@ public async Task<ResourceConfig<Site>> CreateConfigAsync()
// If ContainerImageName is specified and appservice plan doesn’t exist (appServiceplan == null) we will try to create plan with windows container
var farmStrategy = planRG.CreateServerFarmConfig(planResourceGroup, planName, appServiceplan == null && _cmdlet.ContainerImageName != null);

return rgStrategy.CreateSiteConfig(farmStrategy, _cmdlet.Name, this.GetNewConfig(appServiceplan));
return rgStrategy.CreateSiteConfig(farmStrategy, _cmdlet.Name, this.GetNewConfig(appServiceplan)
, (IDictionary<string, string>)CmdletHelpers.ConvertToStringDictionary(_cmdlet.Tag));
}
}

Expand Down
8 changes: 5 additions & 3 deletions src/Websites/Websites/Strategies/SiteStrategy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using Microsoft.Azure.Management.WebSites;
using Microsoft.Azure.Management.WebSites.Models;
using Microsoft.Azure.Management.Internal.Resources.Models;
using System.Collections.Generic;

namespace Microsoft.Azure.Commands.Common.Strategies.WebApps
{
Expand All @@ -28,16 +29,17 @@ static class SiteStrategy
compulsoryLocation: true);

public static ResourceConfig<Site> CreateSiteConfig(this ResourceConfig<ResourceGroup> resourceGroup,
ResourceConfig<AppServicePlan> plan, string siteName, SiteConfig siteConfig = null) =>
ResourceConfig<AppServicePlan> plan, string siteName, SiteConfig siteConfig = null, IDictionary<string, string> tags=null) =>
Strategy.CreateResourceConfig(
resourceGroup,
siteName,
createModel: engine =>
new Site(location: null, name: siteName)
new Site(location: null, name: siteName, tags:tags)
{
//Name = siteName,
SiteConfig = siteConfig,
ServerFarmId = engine.GetId(plan)
ServerFarmId = engine.GetId(plan),
Tags = tags
});
}
}
8 changes: 5 additions & 3 deletions src/Websites/Websites/Utilities/WebsitesClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public WebSiteManagementClient WrappedWebsitesClient
private set;
}

public Site CreateWebApp(string resourceGroupName, string webAppName, string slotName, string location, string serverFarmId, CloningInfo cloningInfo, string aseName, string aseResourceGroupName)
public Site CreateWebApp(string resourceGroupName, string webAppName, string slotName, string location, string serverFarmId, CloningInfo cloningInfo, string aseName, string aseResourceGroupName, IDictionary<string, string> tags = null)
{
Site createdWebSite = null;
string qualifiedSiteName;
Expand All @@ -68,7 +68,8 @@ public Site CreateWebApp(string resourceGroupName, string webAppName, string slo
Location = location,
ServerFarmId = serverFarmId,
CloningInfo = cloningInfo,
HostingEnvironmentProfile = profile
HostingEnvironmentProfile = profile,
Tags = tags
});
}
else
Expand All @@ -80,7 +81,8 @@ public Site CreateWebApp(string resourceGroupName, string webAppName, string slo
Location = location,
ServerFarmId = serverFarmId,
CloningInfo = cloningInfo,
HostingEnvironmentProfile = profile
HostingEnvironmentProfile = profile,
Tags = tags
});
}

Expand Down
17 changes: 16 additions & 1 deletion src/Websites/Websites/help/New-AzWebApp.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Creates an Azure Web App.
```
New-AzWebApp [[-ResourceGroupName] <String>] [-Name] <String> [[-Location] <String>]
[[-AppServicePlan] <String>] [-ContainerImageName <String>] [-EnableContainerContinuousDeployment] [-AsJob]
[-GitRepositoryPath <String>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[-GitRepositoryPath <String>] [-Tag <Hashtable>] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
```

Expand Down Expand Up @@ -378,6 +378,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Tag
Tags are name/value pairs that enable you to categorize resources

```yaml
Type: System.Collections.Hashtable
Parameter Sets: S1
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -TrafficManagerProfile
Resource Id of existing traffic manager profile

Expand Down
17 changes: 16 additions & 1 deletion src/Websites/Websites/help/New-AzWebAppSlot.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ New-AzWebAppSlot [-ResourceGroupName] <String> [-Name] <String> [[-Slot] <String
[[-AppSettingsOverrides] <Hashtable>] [[-AseName] <String>] [[-AseResourceGroupName] <String>]
[-ContainerImageName <String>] [-ContainerRegistryUrl <String>] [-ContainerRegistryUser <String>]
[-ContainerRegistryPassword <SecureString>] [-EnableContainerContinuousDeployment] [-AsJob]
[-DefaultProfile <IAzureContextContainer>] [<CommonParameters>]
[-DefaultProfile <IAzureContextContainer>] [-Tag <Hashtable>] [<CommonParameters>]
```

## DESCRIPTION
Expand Down Expand Up @@ -295,6 +295,21 @@ Accept pipeline input: True (ByValue)
Accept wildcard characters: False
```

### -Tag
Tags are name/value pairs that enable you to categorize resources

```yaml
Type: System.Collections.Hashtable
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### CommonParameters
This cmdlet supports the common parameters: -Debug, -ErrorAction, -ErrorVariable, -InformationAction, -InformationVariable, -OutVariable, -OutBuffer, -PipelineVariable, -Verbose, -WarningAction, and -WarningVariable. For more information, see [about_CommonParameters](http://go.microsoft.com/fwlink/?LinkID=113216).

Expand Down