0
votes

I have an existing Event Grid Topic and want to add an Event Subscription to it, with an existing Azure Function endpoint.

To achieve this I am using Linked Templates. ARM Template validation passes, but deployment fails, with quite a peculiar error:

"InvalidResourceNamespace: "The resource namespace 'subscriptions' is invalid. (Code: InvalidResourceNamespace)"

Here's the raw error:

{
  "code": "DeploymentFailed",
  "message": "At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/DeployOperations for usage details.",
  "details": [
    {
      "code": "InvalidContentLink",
      "message": "Unable to download deployment content from 'https://storagearmtpl.blob.core.windows.net/arm-tpl-service-cd-11111-artifacts/nestedtemplates/eventGridSubscriptionTemplate.json?sv=sasartifactsstring'. The tracking Id is '11111111'. Please see https://aka.ms/arm-deploy for usage details."
    },
    {
      "code": "InvalidResourceNamespace",
      "message": "The resource namespace 'subscriptions' is invalid."
    }
  ]
}

Where sasartifactsstring is a valid artifacts locations sas token. (I'm assuming, it looks correct)

I understand that this error stems from the "type" of the resource in the template being invalid, but as you can see below, it's simply Microsoft.EventGrid/topics/providers/eventSubscriptions.

/nestedtemplates/eventGridSubscriptionTemplate.json

{

    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
      "subscriptionName": {
        "type": "string",
        "metadata": {
          "description": "Name of the event grid subscription"
        }
      },
      "topicName": {
        "type": "string",
        "metadata": {
          "description": "Event grid Topic Name to Subscribe."
        }
      },
      "functionResourceGroupName": {
        "type": "string",
        "metadata": {
          "description": "Resource group name for functionapp"
        }
      },
      "functionAppName": {
        "type": "string",
        "metadata": {
          "description": "function app name"
        }
      },
      "subscriptionId": {
        "type": "string",
        "metadata": {
          "description": "The id string of the Azure subscription"
        }
      },
      "topicResourceGroupName": {
        "type": "string",
        "metadata": {
          "description": "The name of the topic resource group"
        }
      }
    },
    "variables": {},
    "resources": [
      {
        "name": "[concat(parameters('topicName'), '/Microsoft.EventGrid/', parameters('subscriptionName'))]",
        "type": "Microsoft.EventGrid/topics/providers/eventSubscriptions",
        "location": "[resourceGroup().location]",
        "apiVersion": "2020-06-01",
        "properties": {
          "topic": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('topicResourceGroupName'), 'providers/Microsoft.EventGrid/topics/', parameters('topicName'))]",
          "destination": {
                  "endpointType": "AzureFunction",
                  "properties": {
                      "resourceId": "[concat('/subscriptions/', parameters('subscriptionId'), '/resourceGroups/', parameters('functionResourceGroupName'), '/providers/Microsoft.Web/sites/', parameters('functionAppName'), '/functions/HelloWorld')]",
                      "maxEventsPerBatch": 1,
                      "preferredBatchSizeInKilobytes": 64
                  }
              },
          }
        },
        "dependsOn": [
        ]
      }
    ],
    "outputs": {}
  }

/azuredeploy.json

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "_artifactsLocation": {
      "type": "string"
    },
    "_artifactsLocationSasToken": {
      "type": "securestring"
    },
    "functionResourceGroupName": {
      "type": "string"
    },
    "functionAppName": {
      "type": "string"
    },
    "topicName": {
      "type": "string"
    },
    "topicResourceGroupName": {
      "type": "string"
    },
    "subscriptionId": {
      "type": "string"
    }
   },
   "variables": {
     "templateFolder": "nestedtemplates",
     "subscriptionTemplateFileName": "eventGridSubscriptionTemplate.json"
   },
   "resources": [
   {
     "name": "functionsubscription"
     "type": "Microsoft.Resources/deployments",
     "apiVersion": "2017-05-10"
     "resourceGroup": "[parameters('topicResourceGroupName')]",
      "dependsOn": [ ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "subscriptionName": {
            "value": "FunctionSubscription"
          },
          "topicName": {
            "value": "[parameters('topicName')]" 
          },
          "functionResourceGroupName": {
            "value": "[parameters('functionResourceGroupName')]"
          },
          "functionAppName": {
            "value": "[parameters('functionAppName')]"
          },
          "topicResourceGroupName": {
            "value": "[parameters('topicResourceGroupName')]"
          },
          "subscriptionId": {
            "value": "[parameters('subscriptionId')]"
          }
        }
      }
    }
   
]
}
   

azure deploy parameters file

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
  ,
    "functionResourceGroupName": {
      "value": "functionResourceGroup"
    },
    "functionAppName": {
      "value": "functionAppName"
    },
    "subscriptionId": {
      "value": "1111111111"
    },
    "topicName": {
      "value": "topicName"
    },
    "topicResourceGroupName": {
      "value": "topicResourceGroup"
    }
  }

Really not sure what I'm doing wrong here. Worth noting that the first error is annoying as well and I'm not sure why it can't download the deployment content...

update/edit: It's worth noting that the release is using Classic Azure Release Pipelines. And the error comes up during the release.

Looking into the deployment logs for the resource group, I was able to see that the deployment was trying to deploy an invalid resource, with the type starting "subscriptions/.....", so at least I know where the error is coming from. Still investigating what is causing this misread...

1
According to my understanding, you have a custom topic. Now you want to create a subscription for the topic and the subscription will trigger an Azure function. Right?Jim Xu
@JimXu exactly. The weird subscriptions error actually resolved once I put the new entry in my parent/deployment template to the bottom of the resources list. It didn't like that I injected a new resource not at the end I guess. Still bizarre. However I am still dealing with the invalid content link error.mkcoding

1 Answers

0
votes

The cause of the odd 'subscriptions' error was due to the fact that I inserted a new resource into my resources list in my deployment (parent) ARM template, but not at the end of the list.

Once I put the deployment resource that references the new event grid subscription at the end of the resources list, the error did not show up.

azuredeploy.json

resources: [
  {all other existing deployment resources ....},
  {
     "name": "functionsubscription"
     "type": "Microsoft.Resources/deployments",
     "apiVersion": "2017-05-10"
     "resourceGroup": "[parameters('topicResourceGroupName')]",
      "dependsOn": [ ],
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "[concat(parameters('_artifactsLocation'), '/', variables('templateFolder'), '/', variables('subscriptionTemplateFileName'), parameters('_artifactsLocationSasToken'))]",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "subscriptionName": {
            "value": "FunctionSubscription"
          },
          "topicName": {
            "value": "[parameters('topicName')]" 
          },
          "functionResourceGroupName": {
            "value": "[parameters('functionResourceGroupName')]"
          },
          "functionAppName": {
            "value": "[parameters('functionAppName')]"
          },
          "topicResourceGroupName": {
            "value": "[parameters('topicResourceGroupName')]"
          },
          "subscriptionId": {
            "value": "[parameters('subscriptionId')]"
          }
        }
      }
    }
]

However, I am still dealing with the InvalidContentLink error, the main problem of the question has been resolved.