1

I have two different Azure Functions Apps (A & B) that are using the same App Service Plan as opposed a consumption plan. Azure Function App A is in Resource Group 1 and the Azure Function App B is in Resource Group 2. If my App Service Plan is in Resource Group 1, I have no problems scripting out the creation of of Azure Function App A as follows:

az functionapp create --resource-group $serverData.ResourceGroupName \
  --plan  $serverData.FunctionAppServicePlanName \
  --name $serverData.FunctionAppName \
  --storage-account $serverData.LrsStorageAccountName 

However, if I try to create Azure Function App B, the command above will not work. It tells me that it cannot find the App Service Plan. Now, I CAN create this via the portal, but I'd like to script it out.

Is there a way to tell the Azure CLI that the App Service Plan is in Resource Group 1 despite the fact that I'm trying to create the Azure Function App in Resource Group 2?

Michael B
  • 11,887
  • 6
  • 38
  • 74
David Yates
  • 1,935
  • 2
  • 22
  • 38

2 Answers2

4

Documentation https://learn.microsoft.com/en-us/cli/azure/functionapp?view=azure-cli-latest#az-functionapp-create states the following regarding the --plan parameter:

Name or resource id of the function app service plan...

This led me to believe that it is possible to inform the resource id (e.g. /subscriptions/{Subscription Id}/resourceGroups/{Resource Group Name}/providers/Microsoft.Web/serverFarms/{App Service Plan Name}) to the --plan parameter as well.

So, based on your scenario, I run az functionapp create passing the App Service Plan resource id in the --plan parameter. In addition, I added the --debug option to get more details about the execution. Find the last part of the command output and error message below:

--- Command ---

az functionapp create --resource-group "abc" --plan "/subscriptions/{Subscription Id}/resourceGroups/azfuncrg/providers/azfunc" --name "functioappname" --storage-account "/subscriptions/{Subscription Id}/resourceGroups/azfuncrg/providers/Microsoft.Storage/storageAccounts/azfuncstorage"

--- Partial Output ---

...
msrest.http_logger : Response status: 404
msrest.http_logger : Response headers:
msrest.http_logger :     'Cache-Control': 'no-cache'
msrest.http_logger :     'Pragma': 'no-cache'
msrest.http_logger :     'Content-Type': 'application/json; charset=utf-8'
msrest.http_logger :     'Expires': '-1'
msrest.http_logger :     'x-ms-failure-cause': 'gateway'
msrest.http_logger :     'x-ms-request-id': 'd4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'x-ms-correlation-request-id': 'd4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'x-ms-routing-request-id': 'WESTUS2:20180608T002628Z:d4ebc73a-a7ca-45b2-bd59-710aeea1faf2'
msrest.http_logger :     'Strict-Transport-Security': 'max-age=31536000; includeSubDomains'
msrest.http_logger :     'X-Content-Type-Options': 'nosniff'
msrest.http_logger :     'Date': 'Fri, 08 Jun 2018 00:26:28 GMT'
msrest.http_logger :     'Content-Length': '139'
msrest.http_logger : Response content:
msrest.http_logger : b'{"error":{"code":"ResourceNotFound","message":"The Resource \'Microsoft.Web/serverFarms/azfunc\' under resource group \'abc\' was not found."}}'
The plan 'azfunc' doesn't exist

Per debug information, it is looking for the App Service plan (which name was not parsed properly) in the resource group defined by --resource-group parameter.

I might be missing something, it could be a documentation issue, etc.

In any case, I filed the following issue to track/clarify this: https://github.com/Azure/azure-cli/issues/6532

Evandro de Paula
  • 2,532
  • 2
  • 18
  • 27
  • Thanks for the -debug tip and opening a bug. It's unfortunate that I'm going to have to do this by hand for one of my three environments. Thank you. – David Yates Jun 08 '18 at 16:03
3

Edited to add -

Following on from Evandro's answer, and looking through the source code This is a bug and it is not possible.

This is because the code does not parse the Resource ID, instead, it takes the app name and passes the --resource-group variable (I have submitted a fix for this)

The only solution you would have until this is rectified would be to create an App in the same RG and then move it to where you want it.

Original Answer

If you look at the documentation for az functionapp create

for --plan there is the following -

Name or resource id of the function app service plan. Use 'appservice plan create' to get one.

If you specify a name, it expects to find it in the same resource group, if it isn't in the same resource group you need to send the full resource ID

Something like this

$ID = $(az appservice plan show --name $name --resource-group $RG | jq '. | .id')

az functionapp create --resource-group $serverData.ResourceGroupName \
  --plan  $ID \
  --name $serverData.FunctionAppName \
  --storage-account $serverData.LrsStorageAccountName
Michael B
  • 11,887
  • 6
  • 38
  • 74
  • I was going to script moving it to a new resource group, but my storage ( $serverData.LrsStorageAccountName) was created first and its already in another resource group and that's going to be my next problem. I'll just add a warning in my script that this has to be done by hand till the bug is fixed. Thank you. – David Yates Jun 08 '18 at 16:02
  • The link to the source code is returning a 404. Could you look through the repo and see if you can find the code snippet you previously uncovered? – ma499 Sep 13 '19 at 18:38