Azure / Azure/azure-powershell

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

Open
#26,734 3 comments 0 reactions 0 assignees View on GitHub
act-observability-squad App Services bug customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### 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
+ Set-AzWebApp -ResourceGroupName $appServiceResourceGroupName -Name $a ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : CloseError: (:) [Set-AzWebApp], DefaultErrorResponseException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.WebApps.Cmdlets.WebApps.SetAzureWebAppCmdlet`

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

```PowerShell
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

```PowerShell
NA
```

### Module versions

```PowerShell
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

```PowerShell
PS C:\WINDOWS\system32> Resolve-AzError

HistoryId: 37

Message : Operation returned an invalid status code 'BadRequest'
StackTrace : at Microsoft.Azure.Management.WebSites.WebAppsOperations.
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.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
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.