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:
The .json looks like this:
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?