Search code examples
azureazure-functionsterraform-provider-azure

Unexpected error updating Function App plan from consumption to standard. But only for some


While updating Function Apps using Terraform to modify existing resources, I ran into the following. Had 7 function apps. 1 was using a standard, non-consumption plan. The other 6 were on consumption plans. Updated the plan to set all to standard, non-consumption plans.

During terraform apply, for just 2 of the 6 being changed from consumption to non-consumption, and those 2 failures were repeatable. I don't see any differences in the resources that would account for it.

Error: updating Function App "FunctionAppThatFailed" (Resource Group "rg-group-dev"): 
web.AppsClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: 
Code="BadRequest" Message="Number of Web workers must be greater than zero." Details=[{"Message":"Number of Web workers must be greater than zero."},{"Code":"BadRequest"},{"ErrorEntity":{"Code":"BadRequest","ExtendedCode":"04004","Message":"Number of Web workers must be greater than zero.","MessageTemplate":"Number of Web workers must be greater than zero.","Parameters":[]}}]

Any hints, things to check that I may have missed, solutions, etc. are definitely welcome.


Solution

  • I found what was causing those two to fail by comparing against an environment created more recently.

    If you call the Azure REST API endpoint to get the function app definition, you'll find a property "numberOfWorkers" which is set to -1. On the newer function apps it was set to 1. I think the Azure API used to create the consumption based function apps with -1. It currently creates them with a 1 so this should only be a problem on Function Apps created, say, somewhere around early 2021 and before.

    numberOfWorkers value

    Using the REST API I updated that property to 1 on the offending function apps. After that change, the switch to a standard plan worked fine.

    Azure REST API Endpoints used: Get site Update site