0
votes

The functionApp has already been deployed successfully. When attempting to use an Azure DevOps inline powershell script with New-AzDeployment to deploy the following ARM template:

{
    "$schema": "https://schema.management.azure.com/schemas/2018-05-01/subscriptionDeploymentTemplate.json#",
    "contentVersion": "1.0.0.1",
    "parameters": {
        "location": {
            "type": "string",
            "defaultValue": "westus2",
            "metadata": {
                "description": "The region where resources are deployed"
            }
        },
        "functionAppName": {
            "type": "string",
            "defaultValue": "event-driven-func2",
            "metadata": {
                "description": "Func App"
            }
        },
        "eventGridSubscriptionName": {
            "type": "string",
            "defaultValue": "eventSub1",
            "metadata": {
                "description": "Name of Event Grid Subscription"
            }
        },
        "eventGridFunc":{
            "type": "string",
            "defaultValue": "VmAddedListener",
            "metadata": {
                "description" : "Function Name"
            }
        }
    },
    "variables": {
        "functionUrl" : "[concat('https://', parameters('FunctionAppName'),'.azurewebsites.net/runtime/webhooks/eventgrid?functionName=', parameters('eventGridFunc'),'&code=')]"
    },
    "resources": [
        {
            "apiVersion": "2018-01-01",
            "type": "Microsoft.EventGrid/eventSubscriptions",
            "name": "[parameters('eventGridSubscriptionName')]",
            "location": "[parameters('location')]",
            "properties": {
                "destination": {
                    "endpointType": "Webhook",
                    "properties": {
                        "endpointUrl": "[concat(variables('functionUrl'), listKeys(resourceId('Microsoft.Web/sites/host/', parameters('functionAppName'), 'default'),'2016-08-01').masterKey)]"
                    }
                },
                "filter": {
                    "subjectBeginsWith": "",
                    "subjectEndsWith": "",
                    "isSubjectCaseSensitive": false,
                    "includedEventTypes": [
                        "Microsoft.Resources.ResourceActionCancel",
                        "Microsoft.Resources.ResourceActionFailure",
                        "Microsoft.Resources.ResourceActionSuccess",
                        "Microsoft.Resources.ResourceDeleteCancel",
                        "Microsoft.Resources.ResourceDeleteFailure",
                        "Microsoft.Resources.ResourceDeleteSuccess",
                        "Microsoft.Resources.ResourceWriteCancel",
                        "Microsoft.Resources.ResourceWriteFailure",
                        "Microsoft.Resources.ResourceWriteSuccess"
                      ]
                }
            }
        }
    ],
    "outputs": {}
} 

Getting the following error during the release:

"error": { "code": "ResourceNotFound", "message": "The Resource 'Microsoft.Web/sites/abc-rg' under resource group '' was not found." } }'

Do I need to specify the resource group some where in ARM?

2

2 Answers

0
votes

You're declaring a reference to a resource that isn't defined in your ARM template: listKeys(resourceId('Microsoft.Web/sites/host/', parameters('functionAppName'), 'default'),'2016-08-01').masterKey)]

resourceId will only work for resources defined in your ARM template. You can build the resource ID via concatenation and some additional parameters, or define the resource in the same ARM template.

The ideal when using ARM templates is to define the entire environment in a single template (or multiple templates that are all referenced by a single 'master' template), then manage changes to the environment by updating the template accordingly.

0
votes

There is the concept of which scope at which you're conducting the deployment, and I think that might be causing your woes here.

If you're deploying at the Subscription scope, you can deploy resources into multiple Resource Groups, and define the Resource Groups in the deployment as well.

You can always modify this template to also include the definition of the resourceGroup, in the list of resources. You'd just add this, and customize to fit.

   {
      "type": "Microsoft.Resources/resourceGroups",
      "apiVersion": "2018-05-01",
      "location": "eastUs",   // your geo location
      "name": "stackOfTest",  // your desired name
      "properties": {}
    },

It you're deploying at a Subscription Scope, this might solve the issue.

However, you likely are trying to deploy these resources at the Resource Group Scope. That would explain the error, which states that the resource group isn't defined in the template. You can get a template like this when you click 'Export Template' from the Resource Group Level in the Azure portal.

Shows the 'Export Template' button selected in the Azure Web Console / Portal

Simply create a new Deployment at the Resource Group scope from your choice of the Azure portal, PowerShell or dotnet and your template should work as it is.