0
votes

I have an arm template to add new virtual network to an existing Event Hub Namespace.

The problem for is that i have to hard code, or ask as paramameter the vnet and subnet addresprefix.

Is there a way to not have to do this or extract those values and use the on the template ? Vnet exist subnet exist using reference function get's me the values but i get circular definition error if i use it on resource definition.

Tried to get ip's for vnet and subnet by using reference function but i cant use it in the param or variable and in resource i get Circular dependency error.

Basically i like to to this on a clean template.

    "variables": {
        "namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
        "subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
      },
resources : [
       {
          "apiVersion": "2018-01-01-preview",
          "name": "[variables('namespaceVirtualNetworkRuleName')]",
          "type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
          
          "properties": {
            "virtualNetworkSubnetId": "[variables('subNetId')]"
          }
        }
]

But i have to add vnet and subnet with correct ip for this to work.

    "variables": {
    "namespaceVirtualNetworkRuleName": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetRuleName')))]",
    "subNetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName'))]"
  },
  "resources": [
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('eventhubNamespaceName')]",
      "type": "Microsoft.EventHub/namespaces",
      "location": "[parameters('location')]",
      "sku": {
        "name": "Standard",
        "tier": "Standard"
      },
      "properties": { }
    },
    {
      "apiVersion": "2017-09-01",
      "name": "[parameters('vnetRuleName')]",
      "location": "[parameters('location')]",
      "type": "Microsoft.Network/virtualNetworks",
      "properties": { 
        "addressSpace": {
          "addressPrefixes": [
            "a.b.c.0/24",
            "x.y.0.0/16"
          ]
        },
        "subnets": [
          {
            "name": "[parameters('subnetName')]",
            "properties": {
              "addressPrefix": "x.y.z.w/26",
              "serviceEndpoints": [
                {
                  "service": "Microsoft.EventHub"
                }
              ]
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[variables('namespaceVirtualNetworkRuleName')]",
      "type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
      "dependsOn": [
        "[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
      ],
      "properties": {
        "virtualNetworkSubnetId": "[variables('subNetId')]"
      }
    }
  ]

Any idea on hou to remove the vnet part or at list get the ip's before the template and pass them as param ?

1

1 Answers

0
votes

Found out how to make this work. the solution is this :

 "variables": {
  },
  "resources": [
    {
      "apiVersion": "2018-01-01-preview",
      "name": "[parameters('eventhubNamespaceName')]",
      "type": "Microsoft.EventHub/namespaces",
      "location": "[resourceGroup().location]",
      "sku": {
        "name": "Standard",
        "tier": "Standard"
      },
      "properties": { }
    },
    {
      "apiVersion": "2018-01-01-preview", 
      "name": "[concat(parameters('eventhubNamespaceName'), concat('/', parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'), parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')]))]",
      "type": "Microsoft.EventHub/namespaces/VirtualNetworkRules",
      "location": "[resourceGroup().location]",
      "dependsOn": [
        "[concat('Microsoft.EventHub/namespaces/', parameters('eventhubNamespaceName'))]"
      ],
      "properties": {
        "virtualNetworkSubnetId": "[resourceId(parameters('vnetSubscriptioID'), parameters('vnetResorceGroupName'),'Microsoft.Network/virtualNetworks/subnets/', parameters('vnetRuleName'), parameters('subnetName')[copyIndex('subnetcopy')])]"
      },
      "copy": {
        "name": "subnetcopy",
            "count": "[length(parameters('subnetName'))]"
      }
    }
  ]
}

At the end no network part was needed. Updated my solution to be able to deploy more than one subnet at a time.