azure-cli icon indicating copy to clipboard operation
azure-cli copied to clipboard

az appservice plan create causing error: "The server farm with name ... already exists in resource group ..." since new version

Open simonvandermeer opened this issue 7 years ago • 17 comments

Describe the bug We have been using the Azure DevOps Azure CLI task to deploy our infrastructure to Azure. In the most recent version the Azure CLI version it uses went from 2.0.61 to 2.0.67 which broke our pipelines on the 'az appservice plan create' step. It's now issueing the following error:

The server farm with name <appservice plan name> already exists in resource group <resource group name>.

The app service plan does already exist but that wasn't a problem before. It looks like it doesn't work idempotently anymore since version 2.0.67.

To Reproduce Running below commands in that order cause the described error on version 2.0.67 but not on 2.0.66.

az group create --name testappservicerg az appservice plan create --name testappservice --resource-group testappservicerg az appservice plan create --name testappservice --resource-group testappservicerg

Expected behavior No error and the app service plan gets updated with the given settings.

Environment summary Installed with the Azure DevOps Azure CLI task.

Tested locally with 2.0.66 because I still had that version installed. After upgrade to 2.0.67 it gave the described error.

Additional context

simonvandermeer avatar Jul 01 '19 11:07 simonvandermeer

We got the same issue here happening at 2 customers. When we add --debug, we see that there's a /validate POST-request which gives a failure response.

alexdegroot avatar Jul 01 '19 13:07 alexdegroot

Btw, here's a quick work around: Replace the following line: az appservice plan create -g $RG -n $WEBAPPPLAN --sku $SKU By these lines:

WAPL=$(az appservice plan list --query "[?name=='$WEBAPPPLAN']")
if [ "$WAPL" == "[]" ]; then
az appservice plan create -g $RG -n $WEBAPPPLAN --sku $SKU
else
az appservice plan update -g $RG -n $WEBAPPPLAN --sku $SKU
fi

alexdegroot avatar Jul 01 '19 13:07 alexdegroot

I am also getting a similar error for az webapp create: "The site with name <web app name> already exists in resource group <resource group>."

simonvandermeer avatar Jul 01 '19 14:07 simonvandermeer

We are seeing the same issue with az webapp create. Looks like this may have been an intended change in #9323 (webapp: Adding validation for az webapp create & az appservice plan create) That is, #9323 which fixes #9052 (webapp update should validate the RG and webapp exist before trying to run an update)

Is it really necessary to change the behavior of webapp create to fix a problem with webapp update?

onybo avatar Jul 02 '19 10:07 onybo

Most importantly, it conflicts with the design principles about idempotency: https://github.com/Azure/azure-cli/blob/dev/doc/command_guidelines.md#standard-command-types

roycornelissen avatar Jul 02 '19 12:07 roycornelissen

@panchagnula, please can you look into this? Was there a recent change to the command / service that made this command not idempotent?

adewaleo avatar Jul 02 '19 17:07 adewaleo

The validation was added to all creates, Appservice plan & webapp create - this is done by adding a validation check before the create API is called. The validation API call itself is a POST call. Before the validation existed i guess the create command could be used this way az appservice plan create --name testappservice --resource-group testappservicerg az appservice plan create --name testappservice --resource-group testappservicerg

however, that shouldn't be the case we have an update command for AppServiceplan that should be used to update an AppService plan the underlying API call in both create & update is the same - however, from CLI commands perspective these are separate commands & should be used that way.

panchagnula avatar Jul 02 '19 18:07 panchagnula

The Azure CLI guidelines for commands as linked above by @roycornelissen states:

CREATE - standard command to create a new resource. Usually backed server-side by a PUT request. 'create' commands should be idempotent and should return the resource that was created.

One good thing about idempotent create commands is that this enables scripts to use the CLI the same way regardless of the current state of the resource. The script can be made simpler if there is no need to always check if the webapp exists before issuing the az webapp create

If for no other reason the az webapp create and az appservice plan create should follow the same pattern and guidelines that the rest of the CLI is following.

Please reconsider this and allow for the create command to be used in this way: az appservice plan create --name testappservice --resource-group testappservicerg az appservice plan create --name testappservice --resource-group testappservicerg

onybo avatar Jul 02 '19 19:07 onybo

Hi All,

The azure cli Idempotency problem on creating app plans and app services is breaking our build and release pipeline.

Grtz,Ben

benverlinden30 avatar Jul 09 '19 09:07 benverlinden30

The fix has been merged but it’s unclear if or when it is released. And when the hosted Azure DevOps agents will get the update...

roycornelissen avatar Jul 09 '19 10:07 roycornelissen

Roy,

The fix has been merged but it’s unclear if or when it is released. And when the hosted Azure DevOps agents will get the update...

Does this mean that the fix will be applied or only might be applied at some point?

jeffgleed avatar Jul 09 '19 11:07 jeffgleed

The fix will be released on July 17

yugangw-msft avatar Jul 09 '19 11:07 yugangw-msft

Thanks

jeffgleed avatar Jul 09 '19 11:07 jeffgleed

The fix is not yet applied on hosted Azure DevOps agents? We still face the same problem in our CI/CD process. Grtz, Ben

benverlinden30 avatar Jul 24 '19 12:07 benverlinden30

CC @atbagga regarding ADO agent

yugangw-msft avatar Jul 24 '19 15:07 yugangw-msft

ADO agents have a 3 week sprint cycle. The fix just missed the last sprint workload and this won't get picked up until end of next week. It will start reflecting in deployments starting August 5.

Here is the repository where the issues on image generation are tracked - https://github.com/microsoft/azure-pipelines-image-generation

If urgent fix is needed you might need to follow up with the pipelines team on above repo.

atbagga avatar Jul 25 '19 05:07 atbagga

Has this been fixed?

I am still receiving the error when creating a new resource group, using hosted agents. If I re-run the pipeline a second time the error no longer occurs?

This seems to only occur with Azure Function consumption plans i.e. "Server Farm with name 'UKSouthPlan' already exists for subscription '****-****-****-****'."

danponting avatar Mar 18 '20 09:03 danponting