1

I have the following Powershell Script and I'm trying to set 2 Autoscale Rules for a Scale Set I have in Azure.

# Scale Out Rule 
$rule1 = New-AzureRmAutoscaleRule `
  -MetricName "Percentage CPU" `
  -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  -Operator GreaterThanOrEqual `
  -MetricStatistic Average `
  -Threshold 50 `
  -TimeGrain 00:01:00 `
  -TimeWindow 00:05:00 `
  -ScaleActionCooldown 00:01:00 `
  -ScaleActionDirection Increase `
  -ScaleActionScaleType ChangeCount `
  -ScaleActionValue 1

# Scale In Rule
$rule2 = New-AzureRmAutoscaleRule `
  -MetricName "Percentage CPU" `
  -MetricResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  -Operator LessThanOrEqual `
  -MetricStatistic Average `
  -Threshold 30 `
  -TimeGrain 00:01:00 `
  -TimeWindow 00:05:00 `
  -ScaleActionCooldown 00:01:00 `
  -ScaleActionDirection Decrease `
  -ScaleActionScaleType ChangeCount `
  -ScaleActionValue 1

$profile = New-AzureRmAutoscaleProfile `
-DefaultCapacity "2" `
-MaximumCapacity "10" `
-MinimumCapacity "2" `
-Rule $rule1,$rule2 `
-Name "elastic-profile"


Add-AzureRmAutoscaleSetting `
  -Location $myLocation `
  -Name "elastic-setting" `
  -ResourceGroup $myResourceGroup `
  -TargetResourceId /subscriptions/$mySubscriptionId/resourceGroups/$myResourceGroup/providers/Microsoft.Compute/virtualMachineScaleSets/$myScaleSet `
  -AutoscaleProfile $profile

I do not get an error when I run the script. Now the problem is: In Azure the rules don't get mapped correctly; see picture below:

Rules

The .json looks like this:

rules json

Since the script is apparently not getting parsed correctly, the autoscaling doesn't work.

If I update the rules in the Azure Portal, they work.

Has anyone experienced the same?

lenngro
  • 110
  • 10

1 Answers1

3

You are right. This is a known bug in Azure PowerShell version 6.8.1 The product team is working on a fix for this. Meanwhile we are also getting the document updated with this information.

I apologize for the inconvenience as you were following the docs and it is missing this information.

The workaround is to do it in lower PowerShell versions.

Run Get-Module -ListAvailable AzureRM to find the version. If you need to upgrade, see Install Azure PowerShell module.