Azure-cli: 'az webapp create' with different resource group to plan

Created on 7 Feb 2020  Â·  20Comments  Â·  Source: Azure/azure-cli

This is autogenerated. Please review and update as needed.

Describe the bug

It is not possible to create a Web App in a different resource group to the App Service Plan. This functionality is possible in the Azure Portal UI.

Running az webapp create to create a webapp in a different resource group to the service plan results in an error message.

Command Name
az webapp create

Errors:

az webapp create: error: 'NoneType' object has no attribute 'location'

To Reproduce:

$APP_SERVICE_PLAN_NAME = "appserviceplan"
$PLAN_RESOURCE_GROUP_NAME = "appservice-plan-group"
$APP_RESOURCE_GROUP_NAME = "webapp-group"

az group create --name $PLAN_RESOURCE_GROUP_NAME --location australiaeast --subscription $SUBSCRIPTION_ID

az group create --name $APP_RESOURCE_GROUP_NAME --location australiaeast --subscription $SUBSCRIPTION_ID

az appservice plan create --name $APP_SERVICE_PLAN_NAME --resource-group $PLAN_RESOURCE_GROUP_NAME --sku B1 --is-linux

$WEBAPP_NAME = [System.Guid]::NewGuid().ToString()

az webapp create --name $WEBAPP_NAME --resource-group $APP_RESOURCE_GROUP_NAME --plan $APP_SERVICE_PLAN_NAME --runtime """python|3.6""" --query id

Expected Behavior

Environment Summary

Windows-10-10.0.18362-SP0
Python 3.6.6
Shell: cmd.exe

azure-cli 2.0.80 *

Extensions:
db-up 0.1.13
dev-spaces 1.0.3
interactive 0.4.2

Additional Context

Related discussion on the azure-xplat-cli repo: https://github.com/Azure/azure-xplat-cli/issues/3485


Service Attention Web Apps customer-reported

Most helpful comment

I was taking a look at this today. The problem is happening because of this line. The resource group web app is trying to get the service plan from is the same as the web app. So, I see two options here:

* use the method list() from client.app_service_plans and filter for the app service name.

Thanks for the link. Looking in that source code line I found another code path that I could use as an work-around. parse_resource_id should serve instead.
I'm leaving this here for future reference if someone else also stumble on this (and can't be bothered updating az shell or whatever, also the issue was closed as won't fix anyway).

$id = `
az appservice plan show `
  --name shared-service `
  --resource-group networking | `
  ConvertFrom-Json | `
  % { $_.id }

az webapp create `
  --name some-app `
  --resource-group another-group `
  --plan $id `
  --runtime --% "node|10.15"

All 20 comments

Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @AzureAppServiceCLI @antcp

thanks for reporting the issue. we're looking at it.

Can you please run the command with --debug and check the details. Thanks!

Hi @panchagnula

Here is the output:

DEBUG: Command arguments: ['webapp', 'create', '--name', '486097f6-81bc-4702-a983-f64d5aacce22', '--resource-group', 'zz-webapp-group', '--plan', 'zz-appserviceplan', '--runtime', 'python|3.6', '--debug']
DEBUG: Event: Cli.PreExecute []
DEBUG: Event: CommandParser.OnGlobalArgumentsCreate [<function CLILogging.on_global_arguments at 0x039952B8>, <function OutputProducer.on_global_arguments at 0x03896E88>, <function CLIQuery.on_global_arguments at 0x038C0F60>]
DEBUG: Event: CommandInvoker.OnPreCommandTableCreate []
DEBUG: Installed command modules ['acr', 'acs', 'advisor', 'ams', 'apim', 'appconfig', 'appservice', 'backup', 'batch', 'batchai', 'billing', 'botservice', 'cdn', 'cloud', 'cognitiveservices', 'configure', 'consumption', 'container', 'cosmosdb', 'deploymentmanager', 'dla', 'dls', 'dms', 'eventgrid', 'eventhubs', 'extension', 'feedback', 'find', 'hdinsight', 'interactive', 'iot', 'iotcentral', 'keyvault', 'kusto', 'lab', 'managedservices', 'maps', 'monitor', 'natgateway', 'netappfiles', 'network', 'policyinsights', 'privatedns', 'profile', 'rdbms', 'redis', 'relay', 'reservations', 'resource', 'role', 'search', 'security', 'servicebus', 'servicefabric', 'signalr', 'sql', 'sqlvm', 'storage', 'vm']
DEBUG: Loaded module 'acr' in 0.028 seconds.
DEBUG: Loaded module 'acs' in 0.017 seconds.
DEBUG: Loaded module 'advisor' in 0.004 seconds.
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded module 'ams' in 0.014 seconds.
DEBUG: Loaded module 'apim' in 0.004 seconds.
DEBUG: Loaded module 'appconfig' in 0.006 seconds.
DEBUG: Loaded module 'appservice' in 0.020 seconds.
DEBUG: Loaded module 'backup' in 0.007 seconds.
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded module 'batch' in 0.016 seconds.
DEBUG: Loaded module 'batchai' in 0.007 seconds.
DEBUG: Loaded module 'billing' in 0.005 seconds.
DEBUG: Loaded module 'botservice' in 0.007 seconds.
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded module 'cdn' in 0.007 seconds.
DEBUG: Loaded module 'cloud' in 0.004 seconds.
DEBUG: Loaded module 'cognitiveservices' in 0.005 seconds.
DEBUG: Loaded module 'configure' in 0.004 seconds.
DEBUG: Loaded module 'consumption' in 0.007 seconds.
DEBUG: Loaded module 'container' in 0.004 seconds.
DEBUG: Loaded module 'cosmosdb' in 0.013 seconds.
DEBUG: Loaded module 'deploymentmanager' in 0.005 seconds.
DEBUG: Loaded module 'dla' in 0.009 seconds.
DEBUG: Loaded module 'dls' in 0.008 seconds.
DEBUG: Loaded module 'dms' in 0.006 seconds.
DEBUG: Loaded module 'eventgrid' in 0.005 seconds.
DEBUG: Loaded module 'eventhubs' in 0.009 seconds.
DEBUG: Loaded module 'extension' in 0.002 seconds.
DEBUG: Loaded module 'feedback' in 0.002 seconds.
DEBUG: Loaded module 'find' in 0.002 seconds.
DEBUG: Loaded module 'hdinsight' in 0.005 seconds.
DEBUG: Loaded module 'interactive' in 0.001 seconds.
DEBUG: Loaded module 'iot' in 0.007 seconds.
DEBUG: Loaded module 'iotcentral' in 0.003 seconds.
DEBUG: Loaded module 'keyvault' in 0.009 seconds.
DEBUG: Loaded module 'kusto' in 0.004 seconds.
DEBUG: Loaded module 'lab' in 0.008 seconds.
DEBUG: Loaded module 'managedservices' in 0.004 seconds.
DEBUG: Loaded module 'maps' in 0.005 seconds.
DEBUG: Loaded module 'monitor' in 0.016 seconds.
DEBUG: Loaded module 'natgateway' in 0.005 seconds.
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded module 'netappfiles' in 0.008 seconds.
DEBUG: Loaded module 'network' in 0.053 seconds.
DEBUG: Loaded module 'policyinsights' in 0.006 seconds.
DEBUG: Loaded module 'privatedns' in 0.008 seconds.
DEBUG: Loaded module 'profile' in 0.004 seconds.
DEBUG: Loaded module 'rdbms' in 0.015 seconds.
DEBUG: Loaded module 'redis' in 0.006 seconds.
DEBUG: Loaded module 'relay' in 0.008 seconds.
DEBUG: Loaded module 'reservations' in 0.006 seconds.
DEBUG: Loaded module 'resource' in 0.011 seconds.
DEBUG: Loaded module 'role' in 0.010 seconds.
DEBUG: Loaded module 'search' in 0.004 seconds.
DEBUG: Loaded module 'security' in 0.006 seconds.
DEBUG: Loaded module 'servicebus' in 0.009 seconds.
DEBUG: Loaded module 'servicefabric' in 0.005 seconds.
DEBUG: Loaded module 'signalr' in 0.005 seconds.
DEBUG: Loaded module 'sql' in 0.017 seconds.
DEBUG: Loaded module 'sqlvm' in 0.007 seconds.
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded module 'storage' in 0.055 seconds.
DEBUG: Loaded module 'vm' in 0.028 seconds.
DEBUG: Loaded all modules in 0.564 seconds. (note: there's always an overhead with the first module loaded)
DEBUG: Extensions directory: 'C:\Users\daniel.becroft\.azure\cliextensions'
DEBUG: Found 3 extensions: ['db-up', 'dev-spaces', 'interactive']
DEBUG: Extensions directory: 'C:\Users\daniel.becroft\.azure\cliextensions'
DEBUG: Extension compatibility result: is_compatible=True cli_core_version=2.0.80 min_required=2.0.46 max_required=None
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Extensions directory: 'C:\Users\daniel.becroft\.azure\cliextensions'
DEBUG: Loaded extension 'db-up' in 0.213 seconds.
DEBUG: Extensions directory: 'C:\Users\daniel.becroft\.azure\cliextensions'
DEBUG: Extension compatibility result: is_compatible=True cli_core_version=2.0.80 min_required=2.0.63 max_required=None
DEBUG: Event: CommandLoader.OnLoadCommandTable []
DEBUG: Loaded extension 'dev-spaces' in 0.004 seconds.
DEBUG: Extensions directory: 'C:\Users\daniel.becroft\.azure\cliextensions'
DEBUG: Extension compatibility result: is_compatible=True cli_core_version=2.0.80 min_required=2.0.62 max_required=None
DEBUG: Loaded extension 'interactive' in 0.001 seconds.
DEBUG: Event: CommandInvoker.OnPreCommandTableTruncate [<function AzCliLogging.init_command_file_logging at 0x03F63E88>]
INFO: az_command_data_logger : command args: webapp create --name {} --resource-group {} --plan {} --runtime {} --debug
DEBUG: metadata file logging enabled - writing logs to 'C:\Users\daniel.becroft\.azure\commands'.
DEBUG: Event: CommandInvoker.OnPreArgumentLoad [<function register_global_subscription_argument.<locals>.add_subscription_parameter at 0x03F7B4B0>]
INFO: Configured default 'authserver-deploy-test' for arg resource_group_name
DEBUG: Event: CommandInvoker.OnPostArgumentLoad []
DEBUG: Event: CommandInvoker.OnPostCommandTableCreate [<function register_ids_argument.<locals>.add_ids_arguments at 0x03F1BAE0>, <function register_cache_arguments.<locals>.add_cache_arguments at 0x03F1BBB8>]
DEBUG: Event: CommandInvoker.OnCommandTableLoaded []
DEBUG: Event: CommandInvoker.OnPreParseArgs [<function _documentdb_deprecate at 0x04779BB8>]
DEBUG: Event: CommandInvoker.OnPostParseArgs [<function OutputProducer.handle_output_argument at 0x03896ED0>, <function CLIQuery.handle_query_parameter at 0x038C0FA8>, <function register_ids_argument.<locals>.parse_ids_arguments at 0x03F1BB70>, <function handler at 0x04849CD8>]
DEBUG: Getting management service client client_type=WebSiteManagementClient
DEBUG: msrest.universal_http.requests : Configuring retry: max_retries=4, backoff_factor=0.8, max_backoff=90
DEBUG: attempting to read file C:\Users\daniel.becroft\.azure\accessTokens.json as utf-8-sig
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - Authority:Performing instance discovery: ...
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - Authority:Performing static instance discovery
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - Authority:Authority validated via static instance discovery
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - TokenRequest:Getting token from cache with refresh if necessary.
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - CacheDriver:finding with query keys: {'_clientId': '...', 'userId': '...'}
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - CacheDriver:Looking for potential cache entries: {'_clientId': '...', 'userId': '...'}
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - CacheDriver:Found 6 potential entries.
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - CacheDriver:Resource specific token found.
DEBUG: adal-python : 7d68168e-3318-4a96-8206-057bc8e7760c - CacheDriver:Returning token from cache lookup, AccessTokenId: b'<redacted>', RefreshTokenId: b'<redacted>'
DEBUG: msrest.http_logger : Request URL: 'https://management.azure.com/subscriptions/<redacted>/resourceGroups/zz-webapp-group/providers/Microsoft.Web/serverfarms/zz-appserviceplan?api-version=2018-02-01'
DEBUG: msrest.http_logger : Request method: 'GET'
DEBUG: msrest.http_logger : Request headers:
DEBUG: msrest.http_logger :     'Accept': 'application/json'
DEBUG: msrest.http_logger :     'accept-language': 'en-US'
DEBUG: msrest.http_logger :     'User-Agent': 'python/3.6.6 (Windows-10-10.0.18362-SP0) msrest/0.6.10 msrest_azure/0.6.2 azure-mgmt-web/0.42.0 Azure-SDK-For-Python AZURECLI/2.0.80'
DEBUG: msrest.http_logger : Request body:
DEBUG: msrest.http_logger : None
DEBUG: msrest.universal_http : Configuring redirects: allow=True, max=30
DEBUG: msrest.universal_http : Configuring request: timeout=100, verify=True, cert=None
DEBUG: msrest.universal_http : Configuring proxies: ''
DEBUG: msrest.universal_http : Evaluate proxies against ENV settings: True
DEBUG: urllib3.connectionpool : Starting new HTTPS connection (1): management.azure.com:443
DEBUG: urllib3.connectionpool : https://management.azure.com:443 "GET /subscriptions/<redacted>/resourceGroups/zz-webapp-group/providers/Microsoft.Web/serverfarms/zz-appserviceplan?api-version=2018-02-01 HTTP/1.1" 404 162
DEBUG: msrest.http_logger : Response status: 404
DEBUG: msrest.http_logger : Response headers:
DEBUG: msrest.http_logger :     'Cache-Control': 'no-cache'
DEBUG: msrest.http_logger :     'Pragma': 'no-cache'
DEBUG: msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
DEBUG: msrest.http_logger :     'Expires': '-1'
DEBUG: msrest.http_logger :     'x-ms-failure-cause': 'gateway'
DEBUG: msrest.http_logger :     'x-ms-request-id': 'd8a3156a-03c0-4155-911e-9a591cd1d183'
DEBUG: msrest.http_logger :     'x-ms-correlation-request-id': 'd8a3156a-03c0-4155-911e-9a591cd1d183'
DEBUG: msrest.http_logger :     'x-ms-routing-request-id': 'AUSTRALIAEAST:20200217T053246Z:d8a3156a-03c0-4155-911e-9a591cd1d183'
DEBUG: msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
DEBUG: msrest.http_logger :     'X-Content-Type-Options': 'nosniff'
DEBUG: msrest.http_logger :     'Date': 'Mon, 17 Feb 2020 05:32:45 GMT'
DEBUG: msrest.http_logger :     'Content-Length': '162'
DEBUG: msrest.http_logger : Response content:
DEBUG: msrest.http_logger : {"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.Web/serverFarms/zz-appserviceplan' under resource group 'zz-webapp-group' was not found."}}
usage: az webapp create [-h] [--verbose] [--debug]
                        [--output {json,jsonc,table,tsv,yaml,none}]
                        [--query JMESPATH] [--subscription _SUBSCRIPTION]
                        [--resource-group RESOURCE_GROUP_NAME] --name NAME
                        --plan PLAN [--runtime RUNTIME]
                        [--startup-file STARTUP_FILE]
                        [--deployment-container-image-name DEPLOYMENT_CONTAINER_IMAGE_NAME]
                        [--deployment-source-url DEPLOYMENT_SOURCE_URL]
                        [--deployment-source-branch DEPLOYMENT_SOURCE_BRANCH]
                        [--deployment-local-git]
                        [--docker-registry-server-password DOCKER_REGISTRY_SERVER_PASSWORD]
                        [--docker-registry-server-user DOCKER_REGISTRY_SERVER_USER]
                        [--multicontainer-config-type {COMPOSE,KUBE}]
                        [--multicontainer-config-file MULTICONTAINER_CONFIG_FILE]
                        [--tags [TAGS [TAGS ...]]]
az webapp create: error: 'NoneType' object has no attribute 'location'
INFO: az_command_data_logger : exit code: 2
INFO: command ran in 3.219 seconds.

Thanks for sharing the details quickly.

Hi @panchagnula , just checking if there's anything else I need to provide, or if there is any update?

@danielbecroft - sorry i will take a look & reach out if i need anything more. I am on-call & so wasn't able to get to this.

move to S167.

FYI: I'm getting the same error even if the resource group is the same for all resources.

and the version is 2.2.0
`â–¶ az --version
azure-cli 2.2.0

command-modules-nspkg 2.0.3
core 2.2.0
nspkg 3.0.4
telemetry 1.0.4
`

@Kotasudhakarreddy can you look at this issue?

sure, will look in to it @panchagnula

able to repro the issue and will look further to fix the issue.

I was taking a look at this today. The problem is happening because of this line. The resource group web app is trying to get the service plan from is the same as the web app. So, I see two options here:

  • use the method list() from client.app_service_plans and filter for the app service name.
  • add a optional param like -plan-resource-group that the get() method will use.

Which one you think its better? I can implement both!
Thanks!

I was taking a look at this today. The problem is happening because of this line. The resource group web app is trying to get the service plan from is the same as the web app. So, I see two options here:

* use the method list() from client.app_service_plans and filter for the app service name.

Thanks for the link. Looking in that source code line I found another code path that I could use as an work-around. parse_resource_id should serve instead.
I'm leaving this here for future reference if someone else also stumble on this (and can't be bothered updating az shell or whatever, also the issue was closed as won't fix anyway).

$id = `
az appservice plan show `
  --name shared-service `
  --resource-group networking | `
  ConvertFrom-Json | `
  % { $_.id }

az webapp create `
  --name some-app `
  --resource-group another-group `
  --plan $id `
  --runtime --% "node|10.15"

I can confirm that @Luiz-Monad 's solution works as well. So simple.

Little more cross platform
(relies on --query to parse, --out to get string without quotes -- basically no need for jq or sed [ref])

#AppPlanID
az appservice plan show -n "SharedPlan" -g "SharedAppServicePlan" --query "id" --out tsv

We need to figure the best design for supporting this.

FYI trying to use the long version of the plan id in git-bash on windows doesn't work because it tries to do path adjustments. It does work when run from the windows command line. Will probably also work from within linux.

I found out that there is an issue with azure-cli appending a \r character to its output. So the first api call that retrieves the long form app service plan id gets this extra character.

Then when included into the az webapp create call that \r turns into a %0D and breaks the rest call. It returns a 400 error.

You can strip if off by piping the plan call to tr -d '\r'. I ended up just running in native linux to keep my script cleaner.

@calvinsID moving this out by few sprints but lets check if we can figure out a good way (using resourceID instead of name maybe) to support this scenario.

Was this page helpful?
0 / 5 - 0 ratings