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

Created on 1 Jul 2019  路  17Comments  路  Source: Azure/azure-cli

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 \

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

bug

Most helpful comment

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

All 17 comments

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.

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

I am also getting a similar error for az webapp create: "The site with name \

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?

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

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

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.

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

Hi All,

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

Grtz,Ben

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

Roy,

The fix has been merged but it鈥檚 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?

The fix will be released on July 17

Thanks

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

CC @atbagga regarding ADO agent

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.

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 '****-****-****-****'."

Was this page helpful?
0 / 5 - 0 ratings