ARM 模板 - 为合并在单个模板中的 VirtualnetworkGateway 创建模板
ARM Template - Creating a template for VirtualnetworkGateway combined in a single template
我创建了一个模板,用于部署完整的网络解决方案,其中包括 2 个子网、vnet、vnetgw 和 pubip。我正在寻找一种以编程方式引用某些资源 ID 的方法,这样它可以使模板更加动态并且可以使用尽可能多的次数。其次,模板在部署时会产生一个错误,这显然是我之前提到的引用的结果。请看下面的错误;
New-AzResourceGroupDeployment: Line | 3 |
New-AzResourceGroupDeployment -ResourceGroupName rg-vnet-dev -Templat
…
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
| 19:05:58 - Resource Microsoft.Network/virtualNetworkGateways 'rgvnetdev-vnetgw' failed with message '{ "error": {
"code": "InvalidTemplate",
"message": "Unable to process template language expressions for resource
'/subscriptions/77dd2569-6341-4c72-880d-ef59413db99e/resourceGroups/rg-vnet-dev/providers/Microsoft.Network/virtualNetworkGateways/rgvnetdev-vnetgw'
at line '279' and column '9'. 'Unable to evaluate template language
function 'resourceId': the type
'Microsoft.Network/virtualNetworks/subnets' requires '2' resource name
argument(s). Please see
https://aka.ms/arm-template-expressions/#resourceid for usage
details.'",
"additionalInfo": [
{
"type": "TemplateViolation",
"info": {
"lineNumber": 279,
"linePosition": 9,
"path": ""
}
}
] } }
我很乐意分享代码,如果这有助于解决我的问题。该错误与引用 vnet 依赖项以创建 vnetgw 有关。
从错误消息来看,似乎引用的子网 ID 无效。这个函数resourceId格式是
resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...)
在这种情况下,您可能在“279”行缺少 VNet 名称,引用的子网 ID 应如下所示:
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnet1Name'))]"
},
{
"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')]"
}
},
我创建了一个模板,用于部署完整的网络解决方案,其中包括 2 个子网、vnet、vnetgw 和 pubip。我正在寻找一种以编程方式引用某些资源 ID 的方法,这样它可以使模板更加动态并且可以使用尽可能多的次数。其次,模板在部署时会产生一个错误,这显然是我之前提到的引用的结果。请看下面的错误;
New-AzResourceGroupDeployment: Line | 3 | New-AzResourceGroupDeployment -ResourceGroupName rg-vnet-dev -Templat … | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 19:05:58 - Resource Microsoft.Network/virtualNetworkGateways 'rgvnetdev-vnetgw' failed with message '{ "error": { "code": "InvalidTemplate", "message": "Unable to process template language expressions for resource '/subscriptions/77dd2569-6341-4c72-880d-ef59413db99e/resourceGroups/rg-vnet-dev/providers/Microsoft.Network/virtualNetworkGateways/rgvnetdev-vnetgw' at line '279' and column '9'. 'Unable to evaluate template language function 'resourceId': the type 'Microsoft.Network/virtualNetworks/subnets' requires '2' resource name argument(s). Please see https://aka.ms/arm-template-expressions/#resourceid for usage details.'", "additionalInfo": [ { "type": "TemplateViolation", "info": { "lineNumber": 279, "linePosition": 9, "path": "" } } ] } }
我很乐意分享代码,如果这有助于解决我的问题。该错误与引用 vnet 依赖项以创建 vnetgw 有关。
从错误消息来看,似乎引用的子网 ID 无效。这个函数resourceId格式是
resourceId([subscriptionId], [resourceGroupName], resourceType, resourceName1, [resourceName2], ...)
在这种情况下,您可能在“279”行缺少 VNet 名称,引用的子网 ID 应如下所示:
"subnet": {
"id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', parameters('virtualNetworkName'), parameters('subnet1Name'))]"
},
{
"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')]"
}
},