0

My ARM template is defined as followed

 {
  "type": "Microsoft.EventHub/namespaces",
  "sku": {
    "name": "[parameters('SkuName')]",
    "tier": "[parameters('SkuTier')]",
    "capacity": "[parameters('SkuCapacity')]"
  },
  "name": "[parameters('EventHubNamespaceName')]",
  "apiVersion": "2017-04-01",
  "location": "[resourceGroup().location]",
  "properties": {
    "isAutoInflateEnabled": false,
    "maximumThroughputUnits": 0
  }
},


{
  "type": "Microsoft.EventHub/namespaces/eventhubs",
  "name": "[concat(parameters('EventHubNamespaceName'), '/', parameters('Eventhubs')[copyIndex('eventsCopy')].name)]",
  "apiVersion": "2017-04-01",
  "location": "[resourceGroup().location]",
  "properties": {
    "messageRetentionInDays": 1,
    "partitionCount": 2,
    "status": "Active"
  },
  "dependsOn": [
    "[resourceId('Microsoft.EventHub/namespaces', parameters('EventHubNamespaceName'))]"
  ],
  "resources": [
    {
      "type": "authorizationRules",
      "name": "[parameters('Eventhubs')[copyIndex('eventsCopy')].authorizationrulesName]",
      "apiVersion": "2017-04-01",
      "location": "[resourceGroup().location]",
      "scale": null,
      "properties": {
        "rights": [
          "Manage",
          "Listen",
          "Send"
        ]
      },
      "dependsOn": [
        "[parameters('Eventhubs')[copyIndex('eventsCopy')].name]"
      ]
    }
  ],
  "copy": {
    "name": "eventsCopy",
    "count": "[length(parameters('Eventhubs'))]",
    "mode": "serial"

  }
},
{
  "type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups",
  "name": "[concat(parameters('EventHubNamespaceName'), '/', parameters('ConsumerGroups')[copyIndex('ConsumerGroupCopy')].EventhubName, '/',  parameters('ConsumerGroups')[copyIndex('ConsumerGroupCopy')].ConsumerGroupName )]",
  "apiVersion": "2017-04-01",
  "location": "[resourceGroup().location]",
  "scale": null,
  "properties": {
  },
  "dependsOn": [
  ],
  "copy": {
    "name": "ConsumerGroupCopy",
    "count": "[length(parameters('ConsumerGroups'))]",
    "mode": "serial"
  }
},

With this parameter values

 "EventHubNamespaceName": {
        "value": "eventhubnamespace"
    },
    "Eventhubs": {
        "value": [
            {
                "name": "connectionhub",
                "authorizationrulesName": "power"
            },
            {
                "name": "devicehub",
                "authorizationrulesName": "power"
            },
            {
                "name": "inputdata",
                "authorizationrulesName": "power"
            }
        ]
    },
    "ConsumerGroups": {
        "value": [
            {
                "EventhubName": "connectionhub",
                "ConsumerGroupName": "$Default"
            },
            {
                "EventhubName": "devicehub",
                "ConsumerGroupName": "$Default"
            },
            {
                "EventhubName": "devicehub",
                "ConsumerGroupName": "device"
            },
            {
                "EventhubName": "inputdata",
                "ConsumerGroupName": "$Default"
            }
        ]
    },

And this fails with the following error

        Deployment template validation failed: 'The template resource 'Microsoft.EventHub/namespaces/eventhubnamespace/eventhubs/devicehub/consumergroups/$Default' cannot reference itself. Please see https://aka.ms/arm-template-expressions/#reference for usage details.'.

The error tries to tell that the consumergroups reference themself somehow (I think through the depends on) but I can't see where it reference itself.

The reason I defines consumergroups inside another resource is because I want to create multiple consumergroups and think a nested copy is not possible through ARM.

Does anyone see where I've missed the reference of the same resource inside the same resource Group ?

achahbar
  • 901
  • 3
  • 21
  • 47
  • Since your consumergroups resources are dependent on eventhubs resources, you can try including that in the dependsOn for the consumergroups resources. Use the [loop name](https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/copy-resources#depend-on-resources-in-a-loop) `eventsCopy` to mark it as dependent. – stackoverflowusrone Mar 14 '20 at 04:37
  • @stackoverflowusrone I tried that, but it gave me the same error – achahbar Mar 25 '20 at 08:35

1 Answers1

0

I see two problems that are in the template/parameters... (not sure they are your problems though)

1) you have duplicate resource names for your - I'm not sure if that's required for your scenario or not but making them unique would be one fix

2) you have a serial copy loop - that creates implicit dependencies between the resources and the names are ambiguous - so it looks like the resource references itself (or rather it does if the reference is ambiguous) - deploying in parallel (if possible) would solve from this side.

See if that help, I'm going to poke on this internally to see if we have a bug...

bmoore-msft
  • 8,376
  • 20
  • 22