I've been trying to create an Azure Web App inside an App Service Environment using the Powershell commandlets
I can't see anyway to specify that my App Service Environment should be used with either New-AzureWebApp or the New-AzureAppServicePlan commandlets
In the Web portal, you specify your App Service Environment as the location ... but this doesn't seem possible with the Powershell Commandlets (They validate that the location is a valid "regular" Azure location).
To answer my own question:
I found that I could create a new Web App using the New-AzureResourceGroup commandlet and a customised JSON template. I could not find any templates that provisioned a Web App in an ASE in the gallery, but by reverse engineering the template that the portal uses, and modifying the Microsoft.WebSite.0.3.17-preview.json template from the gallery, I could create a WebApp using the command:
New-AzureResourceGroup -Name $ResourceGroupName -Location "Australia Southeast" -TemplateFile $TemplateFile -siteName $SiteName -hostingPlanName $HostingPlanName -hostingEnvironment $HostingEnvironment -siteLocation "Australia Southeast" -workerSize 0 -sku "Premium"
With the $TemplateFile variable containing a Path to the following template file:
http://pastebin.com/VefC0Dz2
This is just the 0.3.17-preview template from the Gallery, with the following modifications:
Add a hostingEnvironment parameter
"parameters": {
"hostingEnvironment": {
"type": "string",
"defaultValue": ""
},
Add the hostingEnvironment property to the Microsoft.Web/serverfarms resource:
"resources": [
{
"apiVersion": "2014-06-01",
"name": "[parameters('hostingPlanName')]",
"type": "Microsoft.Web/serverfarms",
"location": "[parameters('siteLocation')]",
"properties": {
"name": "[parameters('hostingPlanName')]",
"sku": "[parameters('sku')]",
"workerSize": "[parameters('workerSize')]",
"hostingEnvironment": "[parameters('hostingEnvironment')]",
"numberOfWorkers": 0
}
},
{
"apiVersion": "2014-06-01",
"name": "[parameters('siteName')]",
"type": "Microsoft.Web/sites",
"location": "[parameters('siteLocation')]",
"tags": {
"[concat('hidden-related:', '/subscriptions/', parameters('subscriptionId'),'/resourcegroups/', parameters('serverFarmResourceGroup'), '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "empty"
},
"dependsOn": [
"[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
],
"properties": {
"name": "[parameters('siteName')]",
"serverFarm": "[parameters('hostingPlanName')]",
"hostingEnvironment": "[parameters('hostingEnvironment')]"
}
},
I assume this can probably also be done using the Add-AzureResource Commandlet, but I haven't yet attempted this.
Microsoft has added ResourceManager CommandLets to PowerShell. This allows you to perform a deployment. A Website can be created in powerShell using the following commands:
New-AzureRmResource -Location "West Europe" -Properties $props
-ResourceName "Site1" -ResourceType "microsoft.web/sites"
-ResourceGroupName "ResourceGrp1" -Force
You need to create a object for the properties:
$props = @{
HostingEnvironmentId ='/subscriptions/xyz/resourceGroups/ResourceGroup1/providers/Microsoft.Web/hostingEnvironments/ASE1
ServerFarmId = '/subscriptions/XXXX/resourceGroups/EDSGRP1/providers/Microsoft.Web/serverfarms/ASP1'
HostingEnvironment = ResourceGroup1
ClientCertEnabled ='True'
}
You can get idea what the opties of properties are by using Get-AzureRMResource on exising site.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With