How do I work around a possible bug cloning a website using ARM templates?

James Patterson 26 Reputation points
2023-02-09T16:31:13.88+00:00

I have an ARM template that has worked for many months and now reliably fails when deploying.

I have included an extract below.

The template clones an Azure App Service to another. Most of the time the destination AAS will already exist and will just be updated with the new code.

    {
      "type": "Microsoft.Web/sites",
      "apiVersion": "2022-03-01",
      "name": "[variables('website_name')]",
      "location": "[parameters('resourceLocation')]",
      "properties": {
        "cloningInfo": {
          "sourceWebAppId": "[format('/subscriptions/{0}/resourceGroups/xxxxxx/providers/Microsoft.Web/sites/xxxxx', parameters('subscriptionId'))]",
          "sourceWebAppLocation": "North Europe",
          "cloneSourceControl": false,
          "cloneCustomHostNames": false,
          "overwrite": true,
          "appSettingsOverrides": {
            "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference('microsoft.insights/components/xxxxx', '2015-05-01').InstrumentationKey]",
            "XDT_MicrosoftApplicationInsights_Mode": "default",
            "ApplicationInsightsAgent_EXTENSION_VERSION": "~2",
            "Azure_BlobStorage_EndPoint": "[format('https://{0}.blob.{1}/', variables('storageAccount_name'), environment().suffixes.storage)]",
            "Azure_Search_ApiKey": "[variables('search_apiKey')]",
            "Azure_Search_DocumentManagementSystemIndexName": "[format('{0}-dms-index', parameters('tenantPrefix'))]",
            "Azure_Search_ServiceName": "xxxx",
            "WebFarm_RunOnAzureWebsites": "true"
          }
        },
        "serverFarmId": "[format('/subscriptions/{0}/resourcegroups/{1}/providers/Microsoft.Web/serverfarms/{2}', parameters('subscriptionId'), parameters('resourceGroupName'), variables('website_hostingPlanName'))]"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Sql/servers/databases', split(format('{0}/{1}', variables('database_serverName'), variables('database_name')), '/')[0], split(format('{0}/{1}', variables('database_serverName'), variables('database_name')), '/')[1])]",
        "[resourceId('Microsoft.Storage/storageAccounts', variables('storageAccount_name'))]",
        "[resourceId('Microsoft.Resources/deploymentScripts', 'websiteCheckerDeploymentScript')]"
      ]
    },

If the AAS already exists, I add overwrite: true to cloningInfo. This used to work but currently no longer works. If I run it without overwrite, it fails (as expected) with the same message about the resource already existing. The only way I have got around this is to delete the destination resource by hand, wait a few minutes and then run the template. This then works... kind of. It either works fine or fails due to some other internal azure failure about not finding the snapshot etc etc.

I have many instances to update and deleting them one at a time and running the script until it works is a total nightmare as it used to work just fine.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
8,960 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,281 Reputation points Microsoft Employee Moderator
    2023-02-13T16:05:27.02+00:00

    Hi @James Patterson

    I tried your above script through bicep and ran into similar issues. I believe this behavior is now expected. When you clone an app service from the portal, the app can't exist and doesn't have an overwrite option. When you use New-AzWebApp -Name dest-app -SourceWebApp $srcapp there isn't available overwrite or force option and when you run it, it also results in New-AzWebApp: Operation returned an invalid status code 'Conflict' message.

    I've reached out to the team but the only workaround I've been able to determine is delete the existing web app and clone again.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.