Azure / deployment-stacks

Contains Deployment Stacks CLI scripts and releases
MIT License
89 stars 7 forks source link

Failed Deployment Stack Deletion Despite Registered Resource Provider in Subscription #154

Closed JaroslawParadysz closed 5 months ago

JaroslawParadysz commented 7 months ago

Describe the bug I am unable to delete deployment stacks including a Function App and an App Service Plan, although the Storage Account is deleted successfully. The Activity Log indicates a missing Resource Provider for 'sites' and 'serverfarms', despite having the Microsoft.Web resource provider registered for my subscription.

To Reproduce Steps to reproduce the behavior:

  1. Create az deployment stack az stack sub create --name StackTest --template-file environment.test.bicep --parameters environment.test.bicepparam --description "Test Stack" --deny-settings-mode None --location eastus
  2. Delete deployment stack az stack sub delete --delete-all true --name StackTest --verbose
  3. See error in Function App/App Service Plan Activity Log

Expected behavior Deployment stacks should be deleted successfully.

Screenshots image image

Repro Environment Host OS: Windows 10 az bicep version: 0.25.53

Server Debugging Information Correlation ID: 7863d349-4abb-4c98-823c-4516e0877ad Data Center (eg, West Central US, West Europe): eastus

Additional context Bicep script `targetScope='resourceGroup'

var rg = resourceGroup()

param storageAccountType string param functionWorkerRuntime string param storageAccountName string param hostingPlanName string param functionName string

resource storageAccount 'Microsoft.Storage/storageAccounts@2022-05-01' = { name: storageAccountName location: rg.location sku: { name: storageAccountType } kind: 'Storage' properties: { supportsHttpsTrafficOnly: true defaultToOAuthAuthentication: true minimumTlsVersion: 'TLS1_2' } }

resource hostingPlan 'Microsoft.Web/serverfarms@2023-01-01' = { name: hostingPlanName location: rg.location kind: 'linux' sku: { name: 'B1' tier: 'Basic' size: 'B1' family: 'B' capacity: 1 } properties: { perSiteScaling: false elasticScaleEnabled: false maximumElasticWorkerCount: 1 isSpot: false reserved: true isXenon: false hyperV: false targetWorkerCount: 0 targetWorkerSizeId: 0 zoneRedundant: false } }

resource functionApp 'Microsoft.Web/sites@2023-01-01' = { name: functionName location: rg.location kind: 'functionapp,linux' identity: { type: 'SystemAssigned' } properties: { reserved: true serverFarmId: hostingPlan.id siteConfig: { linuxFxVersion: 'DOTNET|6.0' cors: { allowedOrigins: [ 'https://portal.azure.com' ] } ftpsState: 'FtpsOnly' minTlsVersion: '1.2' } httpsOnly: true } }

var currentAppSettings = list('${functionApp.id}/config/appsettings', '2021-03-01').properties

module appSettings './../appsettings.bicep' = { name: '${functionApp.name}-appsettings' scope: rg params: { webAppName: functionApp.name currentAppSettings: currentAppSettings appSettings: { FUNCTIONS_EXTENSION_VERSION: '~4' FUNCTIONS_WORKER_RUNTIME: functionWorkerRuntime AzureWebJobsStorage: 'DefaultEndpointsProtocol=https;AccountName=${storageAccountName};EndpointSuffix=${environment().suffixes.storage};AccountKey=${storageAccount.listKeys().keys[0].value}' } } } `

az stack sub delete command output ` Are you sure you want to delete this stack and the specified resources: resource groups, resources? (y/n): y (DeploymentStackDeleteResourcesFailed) One or more resources could not be deleted. Correlation id: '7863d349-4abb-4c98-823c-4516e0877ad1'. Code: DeploymentStackDeleteResourcesFailed Message: One or more resources could not be deleted. Correlation id: '7863d349-4abb-4c98-823c-4516e0877ad1'. Exception Details: (DeploymentStackOperationFailed) Object reference not set to an instance of an object. Code: DeploymentStackOperationFailed Message: Object reference not set to an instance of an object. Command ran in 486.771 seconds (init: 0.347, invoke: 486.424) Suppress exception: Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/main.py", line 62, in File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/main.py", line 55, in SystemExit: 1

During handling of the above exception, another exception occurred:

Traceback (most recent call last): File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/decorators.py", line 79, in _wrapped_func File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\azure/cli/core/telemetry.py", line 532, in _get_secrets_warning_config File "D:\a_work\1\s\build_scripts\windows\artifacts\cli\Lib\site-packages\knack/config.py", line 147, in getboolean ValueError: Not a boolean: None `

Message in Activity Log No registered resource provider found for location 'eastus' and API version '2023-12-01' for type 'sites'. The supported api-versions are '2023-12-01, 2023-01-01, 2022-09-01, 2022-03-01, 2021-03-01, 2021-02-01, 2021-01-15, 2021-01-01, 2020-12-01, 2020-10-01, 2020-09-01, 2020-06-01, 2019-08-01, 2018-11-01, 2018-02-01, 2016-08-01, 2015-08-01-preview, 2016-03-01, 2015-08-01, 2015-07-01, 2015-06-01, 2015-05-01, 2015-04-01, 2015-02-01, 2014-11-01, 2014-06-01, 2014-04-01, 2014-04-01-preview, 2015-01-01, 2015-11-01, 2016-09-01, 2017-08-01, 2018-12-01-alpha'. The supported locations are 'msftwestus, msfteastus, msfteastasia, msftnortheurope, eastus2stage, centralusstage, southcentralus, southafricanorth, westus, australiaeast, brazilsouth, southeastasia, centralus, japanwest, centralindia, uksouth, canadaeast, koreacentral, francecentral, northeurope, westus2, eastus, westindia, eastus2, australiacentral, germanywestcentral, norwayeast, uaenorth, swedencentral, qatarcentral, switzerlandnorth, northcentralus, ukwest, australiasoutheast, koreasouth, canadacentral, westeurope, southindia, westcentralus, westus3, eastasia, japaneast, jioindiawest, polandcentral, italynorth, israelcentral'.

JaroslawParadysz commented 7 months ago

Has there been any progress, or are there any preliminary findings? Thanks in advance.

dantedallag commented 7 months ago

Hi @JaroslawParadysz,

There are 2 issues here that we are addressing:

  1. The "Object reference not set to an instance of an object" exception being thrown is caused by a bug in our handling of the errored response. We have a fix for this that is checked in and should be rolling out soon.
  2. The underlying deletion error is something we are aware of. The resource type Microsoft.Web/sites/config expects deletion from the data plane and does enable deletion from the control plane, which makes deletion here a bit tricky as stack deletion does not use the data plane. We have a thread here in the context of key vault secrets (which are treated similarly) if you would like to read through and see some of our thoughts/suggestions. Feel free to leave additional questions here or on the other thread.

Thread: https://github.com/Azure/deployment-stacks/issues/142