0

我正在尝试在创建路​​由表时将路由表分配给子网/Vnet。我找不到要添加到脚本中的脚本/属性。有人可以帮我解决这个问题。我正在尝试在创建路​​由表时将路由表分配给子网/Vnet。我找不到要添加到脚本中的脚本/属性。有人可以帮我解决这个问题。

{
"$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')]"
                  }
                }
              ]
        }
    }
]

}

4

2 回答 2

2

我通常会前往https://github.com/Azure/azure-quickstart-templates并在存储库中搜索我想要使用的提供程序类型的示例。我找到了一个例子Microsoft.Network/routeTables,应该可以提供你所寻求的指导。这是特定模板的链接:https ://github.com/Azure/azure-quickstart-templates/blob/master/201-userdefined-routes-appliance/azuredeploy.json

在定义Microsoft.Network/virtualNetworks资源和subnets数组时,子网上有一个名为的属性,routeTable它采用资源 ID。

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

带有两个特定资源的更长的 ARM 模板片段:

...
    {
      "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'))]"
              }
            }
          }
        ]
      }
    },
...
于 2019-05-08T12:46:30.460 回答
0

您需要将此配置放在 Microsoft.Network/subnets 中,如下所示:

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

其中 routeId 是:

             "variables": {
    "routeId": "[resourceId('Microsoft.Network/routeTables', variables('routeName'))]",        
},
于 2019-12-05T19:33:48.770 回答