Azure / arm-template-whatif

A repository to track issues related to what-if noise suppression
MIT License
90 stars 14 forks source link

Microsoft.Web/serverfarms #94

Closed mszadziul87 closed 4 years ago

mszadziul87 commented 4 years ago

Describe the noise

Using What-If results in: InvalidTemplateDeployment - Long running operation failed with status 'Failed'. Additional Info:'The template deployment 'XXX' is not valid according to the validation procedure. The tracking id is '51c383e9-66f5-476e-b336-364bc0315516'. See inner errors for details.' ValidationForResourceFailed - Validation failed for a resource. Check 'Error.Details[0]' for more information. ServerFarmNotFound - The specified app service plan was not found. Resource type (i.e. Microsoft.Storage/storageAccounts) Microsoft.Web/serverfarms apiVersion (i.e. 2019-04-01) 2019-10-01 Client (PowerShell, Azure CLI, or API) PowerShell Relevant ARM Template code (we only need the resource object for the above resourceType and apiVersion, but if it's easier you can include the entire template { "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "_artifactsLocation": { "type": "string" }, "_artifactsLocationSasToken": { "type": "securestring" } }, "variables": { }, "resources": [ { "name": "ServicePlan", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'ServicePlan', '/', 'ServicePlan.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, { "name": "Certificate", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'ServicePlan')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Certificate', '/', 'Certificate.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, { "name": "WebApp", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'Certificate')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'WebApp', '/', 'WebApp.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, { "name": "WebAppSlots", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'WebApp')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'WebAppSlots', '/', 'WebAppSlots.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, { "name": "AppInsights", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'WebAppSlots')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'AppInsights', '/', 'AppInsights.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, { "name": "HostNameBindings", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'AppInsights')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'HostNameBindings', '/', 'HostNameBindings.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } }, //{ // "name": "AppSettings", // "type": "Microsoft.Resources/deployments", // "apiVersion": "2019-10-01", // "dependsOn": [ // "[resourceId('Microsoft.Resources/deployments', 'HostNameBindings')]" // ], // "properties": { // "mode": "Incremental", // "templateLink": { // "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'AppSettings', '/', 'AppSettings.json', parameters('_artifactsLocationSasToken'))]", // "contentVersion": "1.0.0.0" // }, // "parametersLink": { // "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", // "contentVersion": "1.0.0.0" // } // } //}, { "name": "AccessRestrictions", "type": "Microsoft.Resources/deployments", "apiVersion": "2019-10-01", "dependsOn": [ "[resourceId('Microsoft.Resources/deployments', 'HostNameBindings')]" ], "properties": { "mode": "Incremental", "templateLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'AccessRestrictions', '/', 'AccessRestrictions.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" }, "parametersLink": { "uri": "[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion": "1.0.0.0" } } } ], "outputs": { } } Expected response (i.e. "I expected no noise since the template has not been modified since the resources were deployed) The deployment works fine without what-if. Using Linked Template approach with What-If for App Service Plan (Microsoft.Web/serverfarms) and then referencing it in another child template for Certificate (Microsoft.Web/certificates) gives error "ServerFarmNotFound - The specified app service plan was not found."

Child template for Certificate below:

{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "AllParams": { "type": "object" } }, "variables": { }, "resources": [ // Certificate used for SSL Binding on the Web App and Slots { "type": "Microsoft.Web/certificates", "apiVersion": "2016-03-01", "name": "[parameters('AllParams').WebPart.KeyVaultSecretName]", "location": "[resourceGroup().location]", "properties": { "keyVaultId": "[parameters('AllParams').WebPart.KeyVaultId]", "keyVaultSecretName": "[parameters('AllParams').WebPart.KeyVaultSecretName]", "serverFarmId": "[resourceId(parameters('AllParams').ResourceGroupPart.WebAppResourceGroup,'Microsoft.Web/serverfarms', parameters('AllParams').WebPart.ServicePlanName)]" } } ], "outputs": { } }

Current (noisy) response (either include a screenshot of the what-if output, or copy/paste the text)

Error shown above

Additional context

This is happening when you try to run What-If against the deployment in the same resource group. The aim in our company is to put App Service Plan in Resource Group "X" and Web Apps in Resource Group "Y". After that we want to execute What-If against 2 different resource groups deployments but that does not work either e.g.

{ "$schema":"https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion":"1.0.0.0", "parameters":{ "_artifactsLocation":{ "type":"string" }, "_artifactsLocationSasToken":{ "type":"securestring" } }, "variables":{

}, "resources":[ { "name":"ServicePlan", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"XXX", "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'ServicePlan', '/', 'ServicePlan.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } }, { "name":"Certificate", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"YYY", "dependsOn":[ "ServicePlan" ], "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Certificate', '/', 'Certificate.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } }, { "name":"WebApp", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"YYY", "dependsOn":[ "[resourceId('Microsoft.Resources/deployments', 'Certificate')]" ], "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'WebApp', '/', 'WebApp.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } } ], "outputs":{

} }

alex-frankel commented 4 years ago

It's certainly strange that the template would deploy, but what-if would fail in the validation phase.

I'm a bit confused - I see what look like two "mainTemplates" that are similar, but not the same. Are both of these templates failing in the same way? Would it be possible for you to send us a zip of the entire ARM Template + Linked Template so we can repro the issue?

mszadziul87 commented 4 years ago

It's certainly strange that the template would deploy, but what-if would fail in the validation phase.

I'm a bit confused - I see what look like two "mainTemplates" that are similar, but not the same. Are both of these templates failing in the same way? Would it be possible for you to send us a zip of the entire ARM Template + Linked Template so we can repro the issue?

Once again. I am using Linked Templates. They work fine without What-If. The first "master" template e.g. azuredeploy.json refers to a deployment of Service Plan, then Certificate, then Web App. If I run What-If against ServicePlan.json only using the below command the output is correct.

New-AzResourceGroupDeployment -Name ServicePlan -ResourceGroupName "XXX" -TemplateFile "$(System.DefaultWorkingDirectory)/XXX/ARMTemplates/ServicePlan/ServicePlan.json" -TemplateParameterFile "$(System.DefaultWorkingDirectory)/XXX/ARMTemplates/Parameters/SBX.parameters.json" -WhatIf

If I put ServicePlan.json reference inside "master" template like shown above, it fails on the validation that it cannot be found. Service Plan is required by the next child template deployment of Certificate where you have serverFarmId property.

{ "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "parameters": { "AllParams": { "type": "object" } }, "variables": { }, "resources": [ // Certificate used for SSL Binding on the Web App and Slots { "type": "Microsoft.Web/certificates", "apiVersion": "2016-03-01", "name": "[parameters('AllParams').WebPart.KeyVaultSecretName]", "location": "[resourceGroup().location]", "properties": { "keyVaultId": "[parameters('AllParams').WebPart.KeyVaultId]", "keyVaultSecretName": "[parameters('AllParams').WebPart.KeyVaultSecretName]", "serverFarmId": "[resourceId(parameters('AllParams').ResourceGroupPart.ServicePlanResourceGroup,'Microsoft.Web/serverfarms', parameters('AllParams').WebPart.ServicePlanName)]" } } ], "outputs": { } }

Now, the other "master" template I attached and described in "Additional Context" part was because we want to have 2 resource groups. One that holds Service Plan. The other one for Certificate and Web Apps. And we want to reference that in Linked Templates by using resourceGroup property in "master" template. So in resources section you should have:

"resources":[ { "name":"ServicePlan", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"XXX", "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'ServicePlan', '/', 'ServicePlan.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } }, { "name":"Certificate", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"YYY", "dependsOn":[ "ServicePlan" ], "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Certificate', '/', 'Certificate.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } }, { "name":"WebApp", "type":"Microsoft.Resources/deployments", "apiVersion":"2019-10-01", "resourceGroup":"YYY", "dependsOn":[ "[resourceId('Microsoft.Resources/deployments', 'Certificate')]" ], "properties":{ "mode":"Incremental", "templateLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'WebApp', '/', 'WebApp.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" }, "parametersLink":{ "uri":"[concat(parameters('_artifactsLocation'), '/ARMTemplates/', 'Parameters', '/', 'SBX.parameters.json', parameters('_artifactsLocationSasToken'))]", "contentVersion":"1.0.0.0" } } } ]

To sum up. 1) Running What-If against ServicePlan.json alone works fine. 2) Putting ServicePlan.json reference inside a master template and deploying it along with certificate and web apps sequentially as separate child template deployments works fine. 3) Putting ServicePlan.json reference inside a master template and deploying it along with certificate and web apps sequentially as separate child template deployments with What-If does not work. 4) Running What-If against child templates deployments to two different resource groups does not work.

Is this information sufficient or do you still want me to attach my ARM templates (both master and child) and parameters files?

alex-frankel commented 4 years ago

If you can email me at alfran@microsoft.com and attach the entire ARM template + linked template project (including the templates that are working fine). We would like to reproduce on our side.

mszadziul87 commented 4 years ago

Hi,

I just sent you an email with the templates and the scenario that we have in our company.

Any help would be appreciated.

alex-frankel commented 4 years ago

What email address did you send this from? I am not able to find it.

mszadziul87 commented 4 years ago

What email address did you send this from? I am not able to find it.

mateusz.szadziul@wp.pl

alex-frankel commented 4 years ago

Yeah, I think it probably got filtered by exchange. Can you send to alex.j.frankel@gmail.com?

mszadziul87 commented 4 years ago

alex.j.frankel@gmail.com

Sorry, but it gets blocked on send. Have you got some kind of FTP server or should I put it on Google Drive or something and send you the link?

alex-frankel commented 4 years ago

google drive or public github repo would work well. Sorry this is such a pain..

mszadziul87 commented 4 years ago

google drive or public github repo would work well. Sorry this is such a pain..

Sure, please check this link. Thanks.

https://drive.google.com/drive/folders/1a0gXyZYZzWWnZnbumAz5vvuN7B8Sxlu6?usp=sharing

alex-frankel commented 4 years ago

just requested access

mszadziul87 commented 4 years ago

Hi,

I am sorry, but is this case being processed now or are you still having issues with accessing the templates using the aforementioned link?

alex-frankel commented 4 years ago

Apologies for the delay, we now think we know the root cause. The Microsoft.Web provider is too aggressively checking the existence of the service plan. Technically, this is not a what-if issue, we are going to work with the microsoft.web team to get this resolved. Thanks for your patience. I will update this issue with an ETA once we get one.

alex-frankel commented 4 years ago

The fix for this has been committed - we are now waiting for the fix to be deployed

alex-frankel commented 4 years ago

This fix should be deployed. Let us know if you are still seeing this issue.