Azure

Azure Powershell ARM - Count cannot be less than zero

While trying to do a whatif-deployment via -Confirm in Azure PowerShell, I stumbled upon this error message (have seen it a couple of times now actually):

There is no parameter named ‘count’ in the template or parameter file. No other error messages, and no deployment error. The deployment error missing is logical, as there is no actual deployment going on, just an evaluation.

This is the PowerShell command that resulted in the above error:

New-AzResourceGroupDeployment -Confirm ` -ResourceGroup ‘ResourceGroupName’ ` -location ‘westeurope’ ` -templatefile ‘filename’ ` -templateparameterfile ‘filename’ -verbose

After the error appeared, I did a quick web search, and found nothing to solve it. To check if this is an issue with PowerShell or whatif-deployment in itself, I ran the comparable deployment in Az CLI (az deployment group what-if).

The Az CLI evaluated all things correctly, and presented me with a list of the planned changes when deploying this template. I chose to deploy with Az CLI, and the change went through without errors or warnings.

After running the Az CLI, I re-ran the PowerShell command for whatif-deployment. This time the evaluation went through successfully.

I assume this can be attributed to a Preview issue in the PowerShell whatif-deployment (possibly only the -Confirm process, but I did not double check). If you run into a similar problem with PowerShell, try deploying with Az CLI instead. This is the “price you pay” for using preview functionality, I guess.

I have not reported this as an issue, and can’t find it in the whatif-issues. If I encounter it again, I will have the required information to report a clear and concise issue, but for now I can’t describe how to recreate the problem.