1
votes

I am trying to deploy a function app (app service), app service plan and Azure storage account within a nested template, but when I attempt to deploy I get the error:

Status Message: The Resource 'Microsoft.Storage/storageAccounts/saaccountname389' under resource group '<null>' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix (Code:ResourceNotFound)

The part that is causing the template to fail is in appSettings, in the properties of the function app, which attempts to lists the storage account keys. All example templates I have seen (including the export template option in Azure), do this with listKeys(resourceId('Microsoft.Storage/storageAccounts', 'storageaccountnamehere') as per my code below:

"appSettings": [
                                        {
                                            "name": "AzureWebJobsStorage",
                                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('Resources').FunctionStorageAccName,';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Resources').FunctionStorageAccName), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
                                        },
                                        {
                                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('Resources').FunctionStorageAccName,';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Resources').FunctionStorageAccName), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
                                        }
                                    

The only difference I see between my template and others that I have seen, is that mine is nested and I think I may not be using the resourceId properly within a nested template, however I really cannot work out what I need to do differently and ms docs don't point add much clarity : https://docs.microsoft.com/en-us/azure/azure-resource-manager/templates/scope-functions?tabs=azure-powershell.

I have tried many variations of the resourceId function, like including the resource group name, resource group name and subscription ID - all return slightly different errors.

The full nested template is below:

{
        "name":  "data",
        "type": "Microsoft.Resources/deployments",
        "apiVersion": "2017-05-10",
        "resourceGroup": "[variables('ResourceGroups').RGFunction]",
        "dependsOn": [
            "[resourceId('Microsoft.Resources/resourceGroups',variables('ResourceGroups').RGFunction)]"
        ],
        "properties": {
            "mode": "Incremental",
            "template": {
                "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
                "contentVersion": "1.0.0.0",
                "resources": [
                        {
                            "apiVersion": "2018-11-01",
                            "name": "[variables('Resources').FunctionName]",
                            "type": "Microsoft.Web/sites",
                            "kind": "functionapp",
                            "location": "[parameters('locationName')]",
                            "tags": {},
                            "dependsOn": [
                                "[variables('Resources').FunctionASPName]",
                                "[variables('Resources').FunctionStorageAccName]"
                            ],
                            "properties": {
                                "name": "[variables('Resources').FunctionName]",
                                "siteConfig": {
                                    "appSettings": [
                                        {
                                            "name": "FUNCTIONS_EXTENSION_VERSION",
                                            "value": "~3"
                                        },
                                        {
                                            "name": "FUNCTIONS_WORKER_RUNTIME",
                                            "value": "dotnet"
                                        },
                                        {
                                            "name": "AzureWebJobsStorage",
                                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('Resources').FunctionStorageAccName,';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Resources').FunctionStorageAccName), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
                                        },
                                        {
                                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=',variables('Resources').FunctionStorageAccName,';AccountKey=',listKeys(resourceId('Microsoft.Storage/storageAccounts', variables('Resources').FunctionStorageAccName), '2019-06-01').keys[0].value,';EndpointSuffix=','core.windows.net')]"
                                        },
                                        {
                                            "name": "WEBSITE_CONTENTSHARE",
                                            "value": "[concat(toLower(variables('Resources').FunctionName), 'a97a')]"
                                        }
                                    ],
                                    "use32BitWorkerProcess": true
                                },
                                "serverFarmId": "[concat('/subscriptions/', subscription().subscriptionId,'/resourcegroups/', variables('ResourceGroups').RGFunction, '/providers/Microsoft.Web/serverfarms/', variables('Resources').FunctionASPName)]",
                                "clientAffinityEnabled": false
                            }
                        },
                        {
                            "apiVersion": "2018-11-01",
                            "name": "[variables('Resources').FunctionASPName]",
                            "type": "Microsoft.Web/serverfarms",
                            "location": "[parameters('locationName')]",
                            "kind": "",
                            "tags": {},
                            "dependsOn": [],
                            "properties": {
                                "name": "[variables('Resources').FunctionASPName]",
                                "workerSize": "[parameters('FunctionConfiguration').ASPworkerSize]",
                                "workerSizeId": "[parameters('FunctionConfiguration').ASPworkerSize]",
                                "numberOfWorkers": "[parameters('FunctionConfiguration').ASPnumberOfWorkers]"
                            },
                            "sku": {
                                "Tier": "[parameters('FunctionConfiguration').ASPsku]",
                                "Name": "[parameters('FunctionConfiguration').ASPskuCode]"
                            }
                        },
                        {
                            "apiVersion": "2019-06-01",
                            "type": "Microsoft.Storage/storageAccounts",
                            "name": "[variables('Resources').FunctionStorageAccName]",
                            "location": "[parameters('locationName')]",
                            "tags": {},
                            "sku": {
                                "name": "Standard_LRS"
                            },
                            "properties": {
                                "supportsHttpsTrafficOnly": true,
                                "minimumTlsVersion": "TLS1_2"
                            }
                        }
                ]
            }
        }
    }
1
Can you please provide the complete ARM Template so that I can test it?Jagrati Modi

1 Answers

0
votes

you scope the nested template into different resource group than the parent one. it seems like you have the storage account in different RG than functions you want to deploy. resourceId function by default assumes that resource is in this same RG as the one you do the template deployment (in your case - the nested one).

you need to either specify in the resourceId function the name of the resource group the storage account is in or pass the storage account key as securestring parameter into the nested template.

BTW - did you consider using Azure Bicep for IaaC instead ARM?