I'm trying to fix my continious deployment scenario and for this to work an Azure website has to exist and be able to swap between the Staging and Production. We want this website to work in the Standard
pricing tier.
The script I have at the moment creates a new ResourceGroup, Hosting Plan and after these are created, the website itself. The problem I'm facing is the website is always in Free
mode. I should be able to fix this by using the Set-AzureResource
cmdlet, but this one is throwing an message telling me I should specify the Location
. Problem with this is this specific cmdlet doesn't has a Location
parameter.
Set-AzureResource : { "Error": { "Code": "LocationRequired", "Message": "The location property is required for this definition.", "Target": null, "Details": null } }
This is the (simplified) script I'm using to create all of the 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've read the website should inherit the sku
of the specified hosting plan, so I should not need to update it. This does not appear to work for my above script. The hosting plan is specified, but the settings aren't inheritted.
The created hosting plan properties look like this:
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
}
This looks kind of ok to me. Once the website is created, 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, the computeMode, serverFarm, hostingEnvironment and sku aren't set with the properties I set in the $analyticsSite
object.
Therefore I probably need to update the resource, but this throws the error mentioned above.
I've also tried using the New-AzureWebsite
, using Troy Hunt's blogpost as an example. However, this post also relies on using the Set-AzureResource
, so I'll fall into the same problem. A different problem with this example is you can't control on which resource group and hosting plan the site is created which will cause a bit of trouble when searching for the site.