Closed rmarr2 closed 2 years ago
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @antcp, @AzureAppServiceCLI.
WebApp team, please help to look into this question.
Assigning it to myself to repro
@Kotasudhakarreddy , @ThejaChoudary - Following up to see if there is any update on this issue? Thank you
Will look in to it.
@Kotasudhakarreddy the issue still continues, could you please update when the template will be fixed
@Kotasudhakarreddy @KranthiPakala-MSFT @ThejaChoudary This problem persists to this day (July 23, 2022). Why isn't this being resolved?
The work-around proposed by @rmarr2 worked.
For those of you like I who have lost faith in Microsoft resolving this issue, but do not understand the work-around. Here is a guide to help you out:
Ensure you run the New-AzWebApp statement with the additional -debug parameter. This will output the ARM template(s) being executed which you will need in a subsequent step. Note: You will be prompted multiple times to confirm the execution of the command(s).
Standby and await the completion of the command. It will complete with the error described within this issue.
Locate the ARM template which creates the slots themselves. You will find it located immediately above the failed request. The failed request is identified by the following lines:
DEBUG: ============================ HTTP RESPONSE ============================
Status Code: BadRequest
The ARM template itself is the JSON body above this failed response. Here is an example:
Body: { "properties": { "template": { "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "ContentVersion": "1.0.0.0", "Parameters": { "time": { "Type": "string", "DefaultValue": "[utcNow()]" } }, "Variables": { "slotNames": [ "somesourceapp/dev", "somesourceapp/sandbox" ], "webAppName": "SomeSourceApp", "sourceWebAppId": "/subscriptions/..../resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/SomeSourceApp" }, "Resources": [ { "Name": "[concat(variables('webAppName'), '/', variables('slotNames')[copyIndex()])]", "ApiVersion": "2018-02-01", "Type": "Microsoft.Web/sites/slots", "Location": "East US", "Copy": { "Name": "SlotCopy", "Count": "[length(variables('slotNames'))]" }, "Properties": { "ServerFarmId": "OnSchedContainers4", "CloningInfo": { "SourceWebAppId": "[concat(variables('sourceWebAppId'), '/slots/', variables('slotNames')[copyIndex()])]", "CorrelationId": "[guid(variables('slotNames')[copyIndex()], parameters('time'))]" } } } ] }, "mode": "Incremental" } }
4. Locate the variables section, and alter it as described above. Specifically, you must remove the app name and forward slash character from each slotNames entry. In the example below, you would change the following:
"Variables": { "slotNames": [ "somesourceapp/dev", "somesourceapp/sandbox" ],
To the following:
"Variables": { "slotNames": [ "dev", "sandbox" ],
5. Now, you need to trim off the extra JSON content preceding and following the template itself. Specifically, Remove these characters from the beginning:
{ "properties": { "template":
And the following from the end (note the comma at the beginning is to be removed):
, "mode": "Incremental" } }
Your entire JSON template should now look like this **(NOTE: You must use the correct source app and slot names for your situation)**:
{ "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "ContentVersion": "1.0.0.0", "Parameters": { "time": { "Type": "string", "DefaultValue": "[utcNow()]" } }, "Variables": { "slotNames": [ "dev", "sandbox" ], "webAppName": "SomeSourceApp", "sourceWebAppId": "/subscriptions/..../resourceGroups/MyResourceGroup/providers/Microsoft.Web/sites/SomeSourceApp" }, "Resources": [ { "Name": "[concat(variables('webAppName'), '/', variables('slotNames')[copyIndex()])]", "ApiVersion": "2018-02-01", "Type": "Microsoft.Web/sites/slots", "Location": "East US", "Copy": { "Name": "SlotCopy", "Count": "[length(variables('slotNames'))]" }, "Properties": { "ServerFarmId": "OnSchedContainers4", "CloningInfo": { "SourceWebAppId": "[concat(variables('sourceWebAppId'), '/slots/', variables('slotNames')[copyIndex()])]", "CorrelationId": "[guid(variables('slotNames')[copyIndex()], parameters('time'))]" } } } ] }
6. Lastly, save this template (e.g. template.json) and execute the following statement against the target resource group:
```New-AzResourceGroupDeployment -ResourceGroupName YourTargetResourceGroup -TemplateFile "template.json"```
This should successfully deploy the slots into the cloned, target App Service.
Enjoy!
@dariusonsched - Sorry for the inconvenience caused here and thanks for the solution proposed. But Microsoft is always giving its best to the customers. Regarding this issue, the reported user is using the old version( 1.5.0
) of Az.Websites
modules and hope it is same with you. With the current version 2.11.2
of Az.Websites
, the reported issue is not reproducible. issue is fixed. please check and confirm with latest version.
@Kotasudhakarreddy We are using CloudShell within the Azure Portal. The following is the version of Az.Websites
:
2.11.2 Az.Websites /usr/cloudshell/temp Microsoft Azure PowerShell - App Service (Web Apps) service cmdlets for Azure Resource Manager in Windows PowerShell and PowerShell Core.…
Which matches your required version. Yet, we are experiencing the problem described in this Issue, confirmed in the debug output, and for which the work-around resolves.
Appears to remain outstanding or has reappeared as a regression.
@dariusonsched My understanding of the issue is that you are unable to create a new App service with the deployment slots from the existing app service. If this is the issue, I am unable to reproduce from cloud shell. Please find the below repro steps I have followed.
closing as unable to repro the issue. Please file a new issue if this is still a problem.
Description
Following the steps in the following documentation the 4th example shows how to Clone slots with of an existing web app using -IncludeSourceWebAppSlots. This fails with a validation error on the template generated to create the slots
""code": "InvalidTemplate", "message": "Deployment template validation failed: 'The template resource 'usernamedest1234/usernameperapp1/slot' for type 'Microsoft.Web/sites/slots' at line '23' and column '45 ' has incorrect segment lengths. A nested resource type must have identical number of segments as its resource name. A root resource type must have segment length one greater tha n its resource name.
https://docs.microsoft.com/en-us/azure/app-service/app-service-web-app-cloning#cloning-an-existing-app
Steps to reproduce
Create a WebApp with a slot or slots. Follow the example below to Clone the new app along with the slots.
https://docs.microsoft.com/en-us/azure/app-service/app-service-web-app-cloning#cloning-an-existing-app
$srcapp = Get-AzWebApp -ResourceGroupName SourceAzureResourceGroup -Name source-webapp $destapp = New-AzWebApp -ResourceGroupName DestinationAzureResourceGroup -Name dest-webapp -Location "North Central US" -AppServicePlan DestinationAppServicePlan -SourceWebApp $srcapp -IncludeSourceWebAppSlots
The Reason for the exception is documented here "A root level resource must have one less segment in the name than in the resource type." https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/error-invalid-template#solution-2---incorrect-segment-lengths
Using the varaibles in from the template the resulting Name("usernamedest1234567899/usernameperapp1/slot") will have the the same number of segments as the resource Type resulting the error.
{ "Name": "[concat(variables('webAppName'), '/', variables('slotNames')[copyIndex()])]", "ApiVersion": "2018-02-01", "Type": "Microsoft.Web/sites/slots",
Variables": { "slotNames": [ "usernameperapp1/slot", "usernameperapp1/slot2" ], "webAppName": "usernamedest1234567899",
Changing the slotNames to Slot and Slot2 the template will will work. To validate , extract the template that produced the ailure and edited the Slotnames variables and executed the following.
New-AzResourceGroupDeployment -ResourceGroupName usernamergint -TemplateFile "C:\\slots2.json"
Environment data
Module versions
Debug output
Error output