Service Bus ARM teamplate deployemnt issue

Pavan G 186 Reputation points
2022-11-15T15:45:58.527+00:00

Hi Experts,

I am trying to deploy a service bus that has multiple topics, multiple subscriptions inside each topic, and filters inside each subscription.
When I try to deploy via the AzureDevOps pipeline it is failing with the below error.


Deployment template validation failed: 'The template resource '[concat(parameters('ServiceBus_Name'), '/', parameters('Topics')[copyIndex()].Topic_Name, '/', parameters('Topics')[copyIndex()].ListenKey_Name)]' at line '1' and column '1250' is not valid: The template function 'copyIndex' is not expected at this location. The function can only be used in a resource with copy specified. Please see https://aka.ms/arm-copy for usage details.. Please see https://aka.ms/arm-template-expressions for usage details.'.


ARM Template

{  
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",  
  "contentVersion": "1.0.0.0",  
  "parameters": {  
    "apiVersion": {  
      "type": "String"  
    },  
    "Filters": {  
      "type": "Array"  
    },  
    "ServiceBus_Name": {  
      "type": "String"  
    },  
    "Subscriptions": {  
      "type": "Array"  
    },  
    "Topics": {  
      "type": "Array"  
    }  
  },  
  "resources": [  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "location": "[resourceGroup().location]",  
      "name": "[parameters('ServiceBus_Name')]",  
      "properties": {},  
      "sku": {  
        "name": "Standard"  
      },  
      "type": "Microsoft.ServiceBus/namespaces"  
    },  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "copy": {  
        "count": "[length(parameters('Topics'))]",  
        "name": "TopicIteration"  
      },  
      "dependsOn": [  
        "[resourceId('Microsoft.ServiceBus/namespaces', parameters('ServiceBus_Name'))]"  
      ],  
      "location": "[resourceGroup().location]",  
      "name": "[concat(parameters('ServiceBus_Name'),'/', parameters('Topics')[copyIndex()])]",  
      "properties": {  
        "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",  
        "defaultMessageTimeToLive": "P14D",  
        "duplicateDetectionHistoryTimeWindow": "PT10M",  
        "enableBatchedOperations": true,  
        "enableExpress": false,  
        "enablePartitioning": false,  
        "maxSizeInMegabytes": 1024,  
        "requiresDuplicateDetection": false,  
        "status": "Active",  
        "supportOrdering": true  
      },  
      "type": "Microsoft.ServiceBus/namespaces/topics"  
    },  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "dependsOn": [  
        "TopicIteration"  
      ],  
      "location": "[resourceGroup().location]",  
      "name": "[concat(parameters('ServiceBus_Name'), '/', parameters('Topics')[copyIndex()].Topic_Name, '/', parameters('Topics')[copyIndex()].ListenKey_Name)]",  
      "properties": {  
        "rights": [  
          "Listen"  
        ]  
      },  
      "type": "Microsoft.ServiceBus/namespaces/topics/authorizationRules"  
    },  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "dependsOn": [  
        "TopicIteration"  
      ],  
      "location": "[resourceGroup().location]",  
      "name": "[concat(parameters('ServiceBus_Name'), '/', parameters('Topics')[copyIndex()].Topic_Name, '/', parameters('Topics')[copyIndex()].SendKey_Name)]",  
      "properties": {  
        "rights": [  
          "Send"  
        ]  
      },  
      "type": "Microsoft.ServiceBus/namespaces/topics/authorizationRules"  
    },  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "copy": {  
        "count": "[length(parameters('Subscriptions'))]",  
        "name": "SubscriptionIteration"  
      },  
      "dependsOn": [  
        "TopicIteration"  
      ],  
      "location": "[resourceGroup().location]",  
      "name": "[concat(parameters('ServiceBus_Name'), '/', parameters('Topics')[copyIndex()].Topic_Name, '/', parameters('Subscriptions')[copyIndex()].Subscription_Name)]",  
      "properties": {  
        "autoDeleteOnIdle": "P10675199DT2H48M5.4775807S",  
        "deadLetteringOnFilterEvaluationExceptions": false,  
        "deadLetteringOnMessageExpiration": false,  
        "defaultMessageTimeToLive": "P14D",  
        "enableBatchedOperations": true,  
        "forwardTo": "[parameters('Subscriptions')[copyIndex()].forwardToQueue]",  
        "lockDuration": "PT60S",  
        "maxDeliveryCount": 100,  
        "requiresSession": false,  
        "status": "Active"  
      },  
      "type": "Microsoft.ServiceBus/namespaces/topics/subscriptions"  
    },  
    {  
      "apiVersion": "[parameters('apiVersion')]",  
      "copy": {  
        "count": "[length(parameters('Filters'))]",  
        "name": "FilterIteration"  
      },  
      "dependsOn": [  
        "SubscriptionIteration",  
        "TopicIteration"  
      ],  
      "location": "[resourceGroup().location]",  
      "name": "[concat(parameters('ServiceBus_Name'), '/', parameters('Topics')[copyIndex()].Topic_Name, '/', parameters('Subscriptions')[copyIndex()].Subscription_Name, '/', parameters('Filters')[copyIndex()].filter_Name)]",  
      "properties": {  
        "action": {},  
        "filterType": "SqlFilter",  
        "sqlFilter": {  
          "compatibilityLevel": 20,  
          "sqlExpression": "[parameters('Filters')[copyIndex()].filterSQLExpression]"  
        }  
      },  
      "type": "Microsoft.ServiceBus/namespaces/topics/subscriptions/rules"  
    }  
  ],  
  "variables": {}  
}  

Any help or lead will be really helpful.

Regards,
Pavan

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
700 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.