0

我创建了一个模板,旨在部署一个完整的网络解决方案,其中包括 2 个子网、vnet、vnetgw 和 pubip。我正在寻找一种以编程方式引用某些资源 id 的方法,以使模板更具动态性并且可以尽可能多地使用。其次,模板在部署时会产生错误,这显然是我前面提到的参考资料的结果。请参阅下面的错误;

New-AzResourceGroupDeployment:行 | 3 | New-AzResourceGroupDeployment -ResourceGroupName rg-vnet-dev -Templat ... | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| 19:05:58 - 资源 Microsoft.Network/virtualNetworkGateways 'rgvnetdev-vnetgw' 失败并显示消息'{“错误”:{“代码”:“无效模板”,“消息”:“无法处理资源的模板语言表达式”/ subscriptions/77dd2569-6341-4c72-880d-ef59413db99e/resourceGroups/rg-vnet-dev/providers/Microsoft.Network/virtualNetworkGateways/rgvnetdev-vnetgw'在'279'行和'9'列。'无法评估模板语言功能“resourceId”:类型“Microsoft.Network/virtualNetworks/subnets”需要“ 2' 资源名称参数。请参见 https://aka.ms/arm-template-expressions/#resourceid使用详情。'", "additionalInfo": [ { "type": "TemplateViolation", "info": { "lineNumber": 279, "linePosition ": 9, "路径": "" } } ] } }

如果这有助于解决我的问题,我将很乐意分享代码。该错误与引用 vnet 依赖项以创建 vnetgw 有关。

4

2 回答 2

1

从错误消息中,似乎引用的子网 id 无效。这个函数resourceId的格式是

resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...)

在这种情况下,您可能在“279”行缺少 VNet 名称,引用的子网 ID 应如下所示:

 "subnet": {
            "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnet1Name'))]"
          },
于 2020-05-28T06:52:05.003 回答
0
       {
       "type": "Microsoft.Network/virtualNetworkGateways",
       "apiVersion": "2019-12-01",
       "name": "[variables('vnetgwname')]",
       "location": "[parameters('Location')]",
       "dependsOn": [
           "[resourceId('Microsoft.Network/publicIPAddresses',variables('pubIp'))]",
           "[resourceId('Microsoft.Network/virtualNetworks',variables('VNetName'))]"
       ],
       "properties": {
           "ipConfigurations": [
               {
                   "name": "vnetgatewayconfig",
                   "properties": {
                       "publicIPAddress": {
                           "id": "[resourceId('Microsoft.Network/publicIPAddresses',variables('pubIp'))]"
                       },
                       "subnet": {
                           "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets',variables('VNetName'),variables('Uniquegwsubnet'))]"
                       },
                       "privateIPAllocationMethod": "[parameters('publicIPAllocationMethod')]"
                   }
               }
           ],
           "sku": {
               "name": "[parameters('sku')]",
               "tier": "[parameters('sku')]"
           },
           "gatewayType": "[parameters('gatewayType')]",
           "vpnType": "[parameters('VpnType')]",
           "activeActive": false,
           "enableBgp": false,
           "vpnGatewayGeneration": "[parameters('vpnGatewayGeneration')]"
       }
   },
于 2020-05-28T17:30:07.547 回答