Can azure VM sizes be configured by service configuration? Can azure VM sizes be configured by service configuration? azure azure

Can azure VM sizes be configured by service configuration?


The best workaround I've found is to have two different cloud projects. So basically you just create two different cloud projects, add all the same roles into each of them, but have different configurations in each. You just have to be careful to update all the configurations in both places every time you change it. This amounts to having two CSDEFs, as Brent the Programming Simian mentioned already, this is just a concrete way to achieve that.

This also gives you flexibility in other ways. For example, you can have a test site with both HTTP and HTTPS endpoints, but the production site can have only HTTPS.


The VM size is declared in the service definition file. So creating cloud service packages with different sizes require different packages. Ultimately this isn't something that visual studio supports well.

Outside of this, if you're creating a cloud service (PaaS), I'd question why this needs to be done. The best guidance I've recieved is run the smallest VM you need and run as many of them as your load dictates. By having more, smaller instances, your solution ultimately has greater resiliency.


I commented further up, but thought I would provide my solution with powershell. I'm running this prior to building on my CI server, which happens to be TeamCity, but this could be run locally or on CI.

Param(    [string]$RoleType,  #WebRole or WorkerRole    [string]$RoleName,  #RoleName from CSDEF    [string]$VMInstanceSizeIn,  #Options for VM Size: Small, Medium, Large, ExtraLarge, A6, A7    [string]$csDefPath  #File path for ServiceDefinition.csdef for the cloud service project)$timeStampFormat = "g"if ($VMInstanceSizeIn -eq $null) {$VMInstanceSizeIn = "Medium"}Write-Output "$(Get-Date -f $timeStampFormat) - Setting $RoleType role type with RoleName $RoleName VM Size to $VMInstanceSizeIn in ServiceDefinition.csdef prior to building the package file."Try {    $csDefConfig = "$csDefPath\ServiceDefinition.csdef"    Write-Output "$(Get-Date -f $timeStampFormat) - config file location: $csDefConfig"    $csDefConfigXml = [xml](Get-Content $csDefConfig)    Write-Output "$(Get-Date -f $timeStampFormat) - Found ServiceDefinition File at $csDefConfig"    $csDefCurrentXmlNode = $csDefConfigXml.ServiceDefinition.$RoleType | where {$_.Name -eq $RoleName}    $csDefCurrentXmlNode.SetAttribute("vmsize", $VMInstanceSizeIn)    $csDefConfigXml.Save($csDefConfig)    Write-Output "$(Get-Date -f $timeStampFormat) - Successfully saved the ServiceDefinition.csdef file to $csDefConfig"}Catch{    Write-Output "$(Get-Date -f $timeStampFormat) - Powershell Script Error. An error occurred while attempting to modify the ServiceDefinition.csdef file prior to building the solution."      Write-Error -ErrorRecord $_    ##teamcity[buildStatus status='FAILURE' ]    exit(1)}

Please note that at the time this was written I only had to deal with a single web and worker role, so I'm not sure if this was ever tested with multiple worker roles. It should at least be enough to get you started.