Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.27k stars 3.87k forks source link

Set-AzWebApp gives error Bad Request (Instead of helpful output) when encountering a webapp with #26734

Open wnicholscpat opened 5 days ago

wnicholscpat commented 5 days ago

Description

We ran $webApp = Get-AzWebApp -ResourceGroupName $appServiceResourceGroupName -Name $appServiceName then Set-AzWebApp -ResourceGroupName $appServiceResourceGroupName -Name $appServiceName

And get the following output: `Set-AzWebApp : Operation returned an invalid status code 'BadRequest' At line:1 char:1

Expected result is that nothing would change and a warning about existing network rules would be displayed. This should NOT error out.

This should be something more helpful. Like mentioning that one of the Existing! network rules points to something that doesn't exist.

Issue script & Debug output

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
BadRequest

Headers:
Pragma                        : no-cache
Strict-Transport-Security     : max-age=31536000; includeSubDomains
x-ms-ratelimit-remaining-subscription-writes: 199
x-ms-ratelimit-remaining-subscription-global-writes: 2999
x-ms-request-id               : abfcd1f9-ee23-4484-8002-273d992fd6ba
x-ms-correlation-request-id   : abfcd1f9-ee23-4484-8002-273d992fd6ba
x-ms-routing-request-id       : SOUTHCENTRALUS:20241120T023400Z:abfcd1f9-ee23-4484-8002-273d992fd6ba
X-Content-Type-Options        : nosniff
X-Cache                       : CONFIG_NOCACHE
X-MSEdge-Ref                  : Ref A: C1466AF84F7B4A77BB8ADE36B4AE64D5 Ref B: SN4AA2022303035 Ref C:
2024-11-20T02:33:59Z
Cache-Control                 : no-cache
Date                          : Wed, 20 Nov 2024 02:33:59 GMT
X-AspNet-Version              : 4.0.30319
X-Powered-By                  : ASP.NET

Body:
{
  "Code": "BadRequest",
  "Message": "IpSecurityRestriction.VnetSubnetResourceId is invalid.  For request GET
https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Micro
soft.Network/virtualNetworks/***_VPN/taggedTrafficConsumers?api-version=2018-01-01 with clientRequestId
3ba80ac6-e4bf-477d-83b5-c738ded64bf0 and correlationRequestId 3ba80ac6-e4bf-477d-83b5-c738ded64bf0, received a response
 with status code NotFound, error code ParentResourceNotFound, and response content:
{\"error\":{\"code\":\"ParentResourceNotFound\",\"message\":\"Failed to perform 'read' on resource(s) of type
'virtualNetworks/taggedTrafficConsumers', because the parent resource
'/subscriptions/***/resourceGroups/***/providers/Microsoft.Network/virtualNetwork
s/***_VPN' could not be found.\"}}. Request content was ",
  "Target": null,
  "Details": [
    {
      "Message": "IpSecurityRestriction.VnetSubnetResourceId is invalid.  For request GET
https://management.azure.com/subscriptions/***/resourceGroups/***/providers/Micro
soft.Network/virtualNetworks/***_VPN/taggedTrafficConsumers?api-version=2018-01-01 with clientRequestId
3ba80ac6-e4bf-477d-83b5-c738ded64bf0 and correlationRequestId 3ba80ac6-e4bf-477d-83b5-c738ded64bf0, received a response
 with status code NotFound, error code ParentResourceNotFound, and response content:
{\"error\":{\"code\":\"ParentResourceNotFound\",\"message\":\"Failed to perform 'read' on resource(s) of type
'virtualNetworks/taggedTrafficConsumers', because the parent resource
'/subscriptions/***/resourceGroups/***/providers/Microsoft.Network/virtualNetwork
s/***_VPN' could not be found.\"}}.

Environment data

NA

Module versions

ModuleType Version    Name                                ExportedCommands
---------- -------    ----                                ----------------
Script     3.0.3      Az.Accounts                         {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear...
Script     6.0.1      Az.KeyVault                         {Add-AzKeyVaultCertificate, Add-AzKeyVaultCertificateConta...
Script     3.2.1      Az.Websites                         {Add-AzWebAppAccessRestrictionRule, Add-AzWebAppTrafficRou...

Error output

PS C:\WINDOWS\system32> Resolve-AzError

   HistoryId: 37

Message        : Operation returned an invalid status code 'BadRequest'
StackTrace     :    at Microsoft.Azure.Management.WebSites.WebAppsOperations.<UpdateConfigurationWithHttpMessagesAsync>
                 d__53.MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions.<UpdateConfigurationAsync>d__97.
                 MoveNext()
                 --- End of stack trace from previous location where exception was thrown ---
                    at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
                    at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
                    at Microsoft.Azure.Management.WebSites.WebAppsOperationsExtensions.UpdateConfiguration(IWebAppsOper
                 ations operations, String resourceGroupName, String name, SiteConfigResource siteConfig)
                    at Microsoft.Azure.Commands.WebApps.Utilities.WebsitesClient.UpdateWebAppConfiguration(String
                 resourceGroupName, String location, String webSiteName, String slotName, SiteConfig siteConfig,
                 IDictionary`2 appSettings, IDictionary`2 connectionStrings, AzureStoragePropertyDictionaryResource
                 azureStorageSettings)
                    at Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.SetAzureWebAppCmdlet.ExecuteCmdlet()
                    at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
Exception      : Microsoft.Azure.Management.WebSites.Models.DefaultErrorResponseException
InvocationInfo : {Set-AzWebApp}
Line           : Set-AzWebApp -ResourceGroupName $appServiceResourceGroupName -Name $appServiceName
Position       : At line:1 char:1
                 + Set-AzWebApp -ResourceGroupName $appServiceResourceGroupName -Name $a ...
                 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
HistoryId      : 37