Search code examples
jsonazureazure-rm-template

Create Copy Loop for Azure Resource


Hi I'm trying to create a copy loop for an Event Hub, but I keep getting the following error, I can't quite get it right and was hoping someone could see where I was going wrong

Error:

New-AzResourceGroupDeployment : 22:36:18 - Resource Microsoft.EventHub/namespaces 'gor1' failed with message '{
  "error": {
    "message": "The specified service namespace is invalid. CorrelationId: 422868d5-f63c-441f-9741-a2db633a72cf",
    "code": "BadRequest"
  }
}'

The ARM template:

{
  "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "eventHubName": {
      "type": "string",
      "metadata": {
        "description": "Specifies a event name."
      }
    },
    "eventHubNamespaceName": {
      "type": "string",
      "metadata": {
        "description": "Specifies the Namespace name."
      }
    },
    "looplength": {
      "type": "int",
      "defaultValue": 1
    },
    "location": {
      "type": "string",
      "defaultValue": "[resourceGroup().location]",
      "metadata": {
        "description": "Specifies the Azure location for all resources."
      }
    },
    "eventHubSku": {
      "type": "string",
      "defaultValue": "Standard",
      "allowedValues": [ "Basic", "Standard" ],
      "metadata": {
        "description": "Specifies the messaging tier for Event Hub Namespace."
      }
    }
  },
  "variables": {
  },
  "resources": [
    {
      "type": "Microsoft.EventHub/namespaces",
      "apiVersion": "2018-01-01-preview",
      "name": "[concat(Parameters('eventHubNamespaceName'), copyIndex(1))]",
      "location": "[parameters('location')]",
      "sku": {
        "name": "[parameters('eventHubSku')]",
        "tier": "[parameters('eventHubSku')]",
        "capacity": 1
      },
      "copy": {
        "name": "EVLoop",
        "count": "[parameters('looplength')]"
      },
      "properties": {
        "isAutoInflateEnabled": false,
        "maximumThroughputUnits": 0
      }
    },
    {
      "type": "Microsoft.EventHub/namespaces/eventhubs",
      "apiVersion": "2017-04-01",
      "name": "[concat(Parameters('eventHubNamespaceName'), '/', parameters('eventHubName'))]",
      "location": "[parameters('location')]",
      "copy": {
        "name": "EVLoop",
        "count": "[parameters('looplength')]"
      },
      "dependsOn": [
        "[concat(Parameters('eventHubNamespaceName'), copyIndex(1))]"
      ],
      "properties": {
        "messageRetentionInDays": 7,
        "partitionCount": 1
      }
    }
  ]
}

Param file:

{
  "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "eventHubName": {
      "value": "gone"
    },
    "eventHubNamespaceName": {
      "value": "gor"
    },
    "looplength": {
      "value": 1
    },
    "location": {
      "value": "west europe"
    },
    "eventHubSku": {
      "value": "Basic"
    }
  }
}

I've tried to do it so the namespace name and event hub name both iterate together.

Hope that makes sense, thanks in advance :)


Solution

  • The parameter value you are passing for "eventHubNamespaceName" is incorrect.

    As per the Microsoft Azure resource naming restrictions - The Event Hub Namespace name should be of length 6-50 and that can Alphanumerics and hyphens, Start with letter, End with letter or number.

    And currently in your parameter value, you are passing name with less than 6 chars that's the reason deployment is failing.

    Please refer this documentation.