Build a standard-priced Azure site through Powershell

I am trying to fix my continuous deployment scenario, and for this to work, the Azure site must exist and be able to exchange between Staging and Production. We want this website to operate at Standard pricing.

script I am currently creating a new ResourceGroup, Hosting Plan, and after they are created, the site itself. The problem that I encountered is that the site is always in Free mode. I should be able to fix this using the Set-AzureResource , but it throws a message telling me that I should specify Location . The problem with this in this particular cmdlet does not have the Location parameter.

 Set-AzureResource : { "Error": { "Code": "LocationRequired", "Message": "The location property is required for this definition.", "Target": null, "Details": null } } 

This (simplified) script I use to create all resources:

 #Create the resource group New-AzureResourceGroup -Location $location -Name $resourceGroupName -Force #Create the hosting plan $hostingPlanParameters = @{"name" = $hostingPlanName; "sku" = "Standard"; "computeMode" = "Standard"; "workerSize" = "0"; "numberOfWorkers" = "1"} New-AzureResource -ApiVersion 2014-04-01 -Name $hostingPlanName -ResourceGroupName $resourceGroupName ` -ResourceType Microsoft.Web/serverFarms -Location $location ` -PropertyObject $hostingPlanParameters -Verbose -Force #Create the website $analyticsSite = @{"sku" = "Standard"; "webHostingPlan" = $hostingplan; "computeMode" = "Standard"; } New-AzureResource -Name $label -ResourceType Microsoft.Web/sites ` -ResourceGroupName $resourceGroupName -Location $location ` -ApiVersion $apiVersion -PropertyObject $analyticsSite -Force Set-AzureResource -Name $label -ResourceType Microsoft.Web/sites ` -ResourceGroupName $resourceGroupName -ApiVersion $apiVersion ` -PropertyObject $analyticsSite -Force 

I read that the site should inherit sku specified hosting plan, so I do not need to update it. This does not seem to work for my above script. The hosting plan is specified, but the settings are not inherited.

The created hosting plan properties are as follows:

 PropertiesText : { "name": "devHostingPlanWestEU10", "sku": "Standard", "workerSize": 0, "workerSizeId": 0, "numberOfWorkers": 1, "currentWorkerSize": 0, "currentWorkerSizeId": 0, "currentNumberOfWorkers": 1, "status": 0, "webSpace": "ResourceGroupWestEU10-WestEuropewebspace", "subscription": "ad7add9b-8b7a-45df-8e95-0e7fccbr78a5", "adminSiteName": null, "hostingEnvironment": null, "maximumNumberOfWorkers": 0, "planName": null, "perSiteScaling": null, "hostingEnvironmentId": null } 

It looks good to me. After creating the website, these properties are printed:

 PropertiesText : { "name": "Testert10", "state": "Running", "hostNames": [ "testert10.azurewebsites.net" ], "webSpace": "ResourceGroupWestEU10-WestEuropewebspace", ... "repositorySiteName": "Testert10", "owner": null, "usageState": 0, "enabled": true, ... "computeMode": null, "serverFarm": "Default1", "serverFarmId": null, "lastModifiedTimeUtc": "2015-05-21T11:52:30.773", "storageRecoveryDefaultState": "Running", "contentAvailabilityState": 0, "runtimeAvailabilityState": 0, "siteConfig": null, "deploymentId": "Testert10", "trafficManagerHostNames": null, "sku": "Free", "premiumAppDeployed": null, "scmSiteAlsoStopped": false, "targetSwapSlot": null, "hostingEnvironment": null, "microService": "WebSites", "gatewaySiteName": null, "kind": null, "cloningInfo": null, "hostingEnvironmentId": null } 

As you can see, computeMode, serverFarm, hostingEnvironment and sku are not set with the properties that I set in the $analyticsSite object.

Therefore, I probably need to update the resource, but this causes the error mentioned above.

I also tried using New-AzureWebsite using the Troy Hunt blog as an example. However, this post also depends on using Set-AzureResource , so I will get into the same issue. Another problem with this example is that you cannot control in which resource group and hosting plan the site is created, which can cause problems when searching for the site.

+6
source share
3 answers

This is perhaps so easy with the new RM cmdlets. First of all, make sure you have the latest version of Azure PowerShell installed.

First, create an application service plan that defines the standard price level, and then create a web application with an application service plan.

 function Create-AppServicePlan() { #https://msdn.microsoft.com/en-us/library/mt619306.aspx $resource = Find-AzureRmResource -ResourceNameContains $ServicePlanName -ResourceGroupNameContains $ResourceGroupName -ResourceType "Microsoft.Web/ServerFarms" if(!$resource) { # Specify the Tier type that you would like $servicePlan = New-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $ServicePlanName -Location $WebAppLocation -Tier Standard -NumberofWorkers 1 -WorkerSize "Small" } } 

Then create a web application with an application maintenance plan as a parameter.

 function Create-AzureRmWebApp() { #https://msdn.microsoft.com/en-us/library/mt619250.aspx $resource = Find-AzureRmResource -ResourceNameContains $WebAppName -ResourceGroupNameContains $ResourceGroupName -ResourceType "Microsoft.Web/sites" if(!$resource) { $webApp = New-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -Location $WebAppLocation -AppServicePlan $ServicePlanName } } 

This is a complete working script that has been verified.

 $ServicePlanName = "PSScriptAppServicePlann" $WebAppName = "WebAppByPSlooksCool" $ResourceGroupName = "MyResourceGroup" $WebAppLocation = "australiaeast" $ErrorActionPreference = "Stop" # Step 1: Create the application service plan Create-AppServicePlan # Step 2: Create the web app using the service plan name. Create-AzureRmWebApp function Create-AzureRmWebApp() { #https://msdn.microsoft.com/en-us/library/mt619250.aspx $resource = Find-AzureRmResource -ResourceNameContains $WebAppName -ResourceGroupNameContains $ResourceGroupName -ResourceType "Microsoft.Web/sites" if(!$resource) { $webApp = New-AzureRmWebApp -ResourceGroupName $ResourceGroupName -Name $WebAppName -Location $WebAppLocation -AppServicePlan $ServicePlanName } } function Create-AppServicePlan() { #https://msdn.microsoft.com/en-us/library/mt619306.aspx $resource = Find-AzureRmResource -ResourceNameContains $ServicePlanName -ResourceGroupNameContains $ResourceGroupName -ResourceType "Microsoft.Web/ServerFarms" if(!$resource) { # Specify the Tier type that you would like $servicePlan = New-AzureRmAppServicePlan -ResourceGroupName $ResourceGroupName -Name $ServicePlanName -Location $WebAppLocation -Tier Standard -NumberofWorkers 1 -WorkerSize "Small" } } 
+5
source

The problem is that you created your site in the standard free App Service Plan (aka Server Farm or in terms of web hosting - they are all the same), called "Default1". However, the application maintenance plan that you scaled to a standard size was different, called "devHostingPlanWestEU10".

To create a site in an existing Application Service Plan, use the following command:

(split into several lines for readability)

 New-AzureResource -Name <YourSiteName> -Location "West US" -ResourceGroupName <YourResourceGroupName> -ApiVersion 2014-11-01 -ResourceType "Microsoft.Web/sites" -PropertyObject @{ "serverFarm" = "<Your service plan name>" } 
+1
source

With the New Azure Resource Manager cmdlet. You can create a new application service plan and submit it to the New-AzureRmWebApp Team.

New-AzureRmAppServicePlan -Name StdPlan -Location <"Location"> -ResourceGroupName <"ResourceGroupName"> - Level Standard

New-AzureRmWebApp -ResourceGroupName <"ResourceGroupName"> -Name <"WebAppname"> -Location <"Location"> -AppServicePlan StdPlan

Link: https://docs.microsoft.com/en-us/azure/app-service-web/app-service-web-app-azure-resource-manager-powershell

0
source

Source: https://habr.com/ru/post/987665/


All Articles