Vikranth S
Vikranth S

Reputation: 491

Assign UDRs/Route Tables to a Subnet With ARM template

I am trying to assign Rout tables to a Subnet/Vnet while creating route tables. I couldn't find a script/property to add into the script. Could someone please help me on this. I am trying to assign Rout tables to a Subnet/Vnet while creating route tables. I couldn't find a script/property to add into the script. Could someone please help me on this.

{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
    "location": {
        "type": "string"
    },
    "name": {
        "type": "string"
    },
    "disableBgpRoutePropagation": {
        "type": "string"
    },
    "Spoke2AddressPrefix" :{
        "type": "string"
    },
    "HopIpaddress" : {
        "type": "string"
    },
    "VnetRGName" : {
        "type": "string"
    },
    "VnetName" : {
        "type": "string"
    },
    "SubnetName" : {
        "type": "string"
    }
},
"resources": [
    {
        "name": "[parameters('name')]",
        "type": "Microsoft.Network/routeTables",
        "apiVersion": "2018-08-01",
        "location": "[parameters('location')]",
        "dependsOn": [],
        "properties": {
            "disableBgpRoutePropagation": "[parameters('disableBgpRoutePropagation')]",
            "routes": [
                {
                  "name": "Spoke1-Hub",
                  "id" : "[concat(resourceId( parameters('VnetRGName'), 'Microsoft.Network/virtualNetworks', parameters('Vnetname')), 'Microsoft.Network/virtualNetworks/subnets', parameters('subnetname'))]",
                  "properties": {
                    "addressPrefix": "[parameters('Spoke2AddressPrefix')]",
                    "nextHopType": "VirtualAppliance",
                    "nextHopIpAddress": "[parameters('HopIpaddress')]"
                  }
                }
              ]
        }
    }
]

}

Upvotes: 0

Views: 4183

Answers (2)

LMG
LMG

Reputation: 1370

You need to put this configuration in the Microsoft.Network/subnets as follow:

       {
        "type": "Microsoft.Network/virtualNetworks/subnets",
        "apiVersion": "2019-09-01",
        "name": "[parameters('name')",
        "dependsOn": [
            "[variables('routeId')]"            
        ],
        "properties": {
            "routeTable": {
                "id": "[variables('routeId')]"
            },

Where routeId is:

             "variables": {
    "routeId": "[resourceId('Microsoft.Network/routeTables', variables('routeName'))]",        
},

Upvotes: 0

Stringfellow
Stringfellow

Reputation: 2908

I typically head over to https://github.com/Azure/azure-quickstart-templates and search the repository for example of the provider types I want to work with. I found an example with Microsoft.Network/routeTables that should provide the guidance you seek. Here is the link to the specific template: https://github.com/Azure/azure-quickstart-templates/blob/master/201-userdefined-routes-appliance/azuredeploy.json

When defining the Microsoft.Network/virtualNetworks resource and the subnets array, there is a property on the subnet called routeTable that takes the resource ID.

"routeTable": {
                "id": "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
              }

A longer snippet of the ARM template with the two specific resources:

...
    {
      "type": "Microsoft.Network/routeTables",
      "name": "[variables('routeTableName')]",
      "apiVersion": "2015-06-15",
      "location": "[parameters('location')]",
      "properties": {
        "routes": [
          {
            "name": "VirtualApplianceRouteToSubnet3",
            "properties": {
              "addressPrefix": "[variables('subnet3Prefix')]",
              "nextHopType": "VirtualAppliance",
              "nextHopIpAddress": "[variables('NvmPrivateIPAddress')]"
            }
          }
        ]
      }
    },
    {
      "apiVersion": "2015-06-15",
      "type": "Microsoft.Network/virtualNetworks",
      "name": "[variables('VNetName')]",
      "location": "[parameters('location')]",
      "dependsOn": [
        "[concat('Microsoft.Network/routeTables/', variables('routeTableName'))]",
        "[concat('Microsoft.Network/networkSecurityGroups/', variables('nsgname'))]"
      ],
      "properties": {
        "addressSpace": {
          "addressPrefixes": [
            "[variables('VNetAddressPrefix')]"
          ]
        },
        "subnets": [
          {
            "name": "[variables('Subnet1Name')]",
            "properties": {
              "addressPrefix": "[variables('Subnet1Prefix')]",
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgname'))]"
              },
              "routeTable": {
                "id": "[resourceId('Microsoft.Network/routeTables', variables('routeTableName'))]"
              }
            }
          },
          {
            "name": "[variables('Subnet2Name')]",
            "properties": {
              "addressPrefix": "[variables('Subnet2Prefix')]",
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgname'))]"
              }
            }
          },
          {
            "name": "[variables('Subnet3Name')]",
            "properties": {
              "addressPrefix": "[variables('Subnet3Prefix')]",
              "networkSecurityGroup": {
                "id": "[resourceId('Microsoft.Network/networkSecurityGroups', variables('nsgname'))]"
              }
            }
          }
        ]
      }
    },
...

Upvotes: 2

Related Questions