Azure / azure-rest-api-specs

The source for REST API specifications for Microsoft Azure.
MIT License
2.68k stars 5.1k forks source link

webapp:New-AzResourceGroupDeployment for web site with slot fails if template contains "cloningInfo" #7276

Open rudfoss opened 5 years ago

rudfoss commented 5 years ago

Description

I'm trying to deploy a web app with two slots (production, deploytarget). Everything works fine the first time, but subsequent runs with the web app already present fail with an error indicating the site already exists. I was under the impression that ARM templates should always be able to run even if the resources already exist? If not is there a quick way to tell ARM that it should not touch the slot if it exists?

The problem goes away if I remove the "cloningInfo" options from the template. It appears there is a problem with cloning onto an existing app service.

"cloningInfo": {
  "sourceWebAppId": "[resourceId('Microsoft.Web/sites', variables('webAppName'))]",
  "overwrite": true
}

Script/Steps for Reproduction

New-AzResourceGroupDeployment # with provided template

This is the template that is used:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "environment": {
      "type": "string",
      "allowedValues": [
        "devtest",
        "test",
        "stag",
        "prod"
      ]
    },

    "skuName": {
      "type": "string",
      "defaultValue": "S1"
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1
    },

    "nodeVersion": {
      "type": "string",
      "defaultValue": "10.6.0"
    },

    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]"
    },
    "deployTargetSlotName": {
      "type": "string",
      "defaultValue": "deploytarget"
    }
  },
  "variables": {
    "appServiceName": "[concat('TestAppServiceName-ASP-', parameters('environment'))]",
    "webAppName": "[concat('TestAppServiceName-APP-', parameters('environment'))]"
  },
  "resources": [
    {
      "name": "[variables('appServiceName')]",
      "type": "Microsoft.Web/serverfarms",
      "kind": "app",
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "apiVersion": "2016-09-01",
      "location": "[parameters('location')]",
      "scale": null,
      "properties": {
          "name": "[variables('appServiceName')]"
      }
    },
    {
      "name": "[variables('webAppName')]",
      "type": "Microsoft.Web/sites",
      "apiVersion": "2018-02-01",
      "location": "[parameters('location')]",
      "tags": {
        "displayName": "[variables('webAppName')]"
      },
      "properties": {
        "name": "[variables('webAppName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]",
        "clientAffinityEnabled": false,
        "httpsOnly": true,
        "siteConfig": {
          "alwaysOn": true,
          "phpVersion": ""
        }
      },
      "dependsOn": [
        "[variables('appServiceName')]"
      ],
      "resources": [
        {
          "name": "[parameters('deployTargetSlotName')]",
          "type": "slots",
          "apiVersion": "2018-02-01",
          "dependsOn": [
            "[variables('webAppName')]"
          ],
          "location": "[parameters('location')]",
          "properties": {
            "enabled": false,
            "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServiceName'))]",
            "clientAffinityEnabled": false,
            "httpsOnly": true,
            "cloningInfo": {
              "sourceWebAppId": "[resourceId('Microsoft.Web/sites', variables('webAppName'))]",
              "overwrite": true
            }
          }
        }
      ]
    }
  ],
  "outputs": {
    "webappName": {
      "type": "string",
      "value": "[variables('webAppName')]"
    }
  }
}

Module Version

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     0.6.1      Az.Profile                          {Add-AzEnvironment, Clear-AzContext, Clear-AzDefault, Connect-AzAccount...}
Script     0.6.1      Az.Storage                          {Add-AzRmStorageContainerLegalHold, Add-AzStorageAccountNetworkRule, Disable-AzStorageDeleteRetentionPolicy, Enable-AzStorageDeleteRetentionPolicy...}
Manifest   3.1.0.0    Microsoft.PowerShell.Management     {Add-Computer, Add-Content, Checkpoint-Computer, Clear-Content...}
Manifest   3.0.0.0    Microsoft.PowerShell.Security       {ConvertFrom-SecureString, ConvertTo-SecureString, Get-Acl, Get-AuthenticodeSignature...}
Manifest   3.1.0.0    Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object...}
Manifest   3.0.0.0    Microsoft.WSMan.Management          {Connect-WSMan, Disable-WSManCredSSP, Disconnect-WSMan, Enable-WSManCredSSP...}
Script     1.2        PSReadline                          {Get-PSReadlineKeyHandler, Get-PSReadlineOption, Remove-PSReadlineKeyHandler, Set-PSReadlineKeyHandler...}

Environment Data

Name                           Value
----                           -----
PSVersion                      5.1.17134.407
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.17134.407
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Debug Output

13:23:59 - Resource Microsoft.Web/sites/slots 'TestAppServiceName-ASP-devtest/deploytarget' failed with message '{
  "status": "Failed",
  "error": {
    "code": "ResourceDeploymentFailure",
    "message": "The resource operation completed with terminal provisioning state 'Failed'.",
    "details": [
      {
        "message": "Conflict\r\nDetail: Site with name TestAppServiceName-ASP-devtest(deploytarget) already exists.\r\nExtendedCode: 04008\r\n   at Microsoft.Web.Hosting.Administration.Csm.Common.Clients.GeoClientBase.GetResponse[T](HttpWebRequest request, Boolean reThrowOnHostUnavailability, HttpStatusCode[]
supressLogForHttpCodes)\r\n   at Microsoft.Web.Hosting.Administration.GeoScale.Sql.WebSiteCloneManager.StartSiteRestore(SiteClone clone, Operation cloneOperation)\r\n"
      }
    ]
  }
}'
cormacpayne commented 5 years ago

@panchagnula Hey Sisira, would you mind taking a look at this issue? If this should be redirected to the ARM team, please let me know and I'll reassign accordingly.

panchagnula commented 5 years ago

@Nking92 , not sure if there is a known issue with passing cloningInfo in an ARM Template with slot.

nking-1 commented 5 years ago

The overwrite flag is currently not working properly, which is why you're getting a conflict. We'll try to get that fixed soon. Sorry for the inconvenience.

rudfoss commented 5 years ago

No problem. Thanks for looking into this!

rbedger commented 5 years ago

no update on this? still seeing this issue.

panchagnula commented 5 years ago

@Nking92 is this fixed now? can you please update this issue?

SuchitChoudhury commented 5 years ago

@Nking92 I am getting the issue for one of my customers who is using ARM template for deployment. I did reproduce the issue at my end. Do we have an ETA when is this going to be fixed?

panchagnula commented 5 years ago

@naveedaz for me to follow-up with on this.

marcodiasaraujo commented 5 years ago

I have the same issue... Any solution?

panchagnula commented 5 years ago

no solution as yet - this is a backend bug so moving to the right GitHub alias

simonethreechillies commented 4 years ago

Is there any update in regards to this issue?

PaulVrugt commented 3 years ago

this issue seems already fixed

m1dst commented 3 years ago

Is this issue ever going to be fixed? It is impossible to redeploy a template when using cloningInfo unless you know ahead of time if the resource already exists and set the overwrite property accordingly. This goes against the whole premise of ARM.