我目前正在编写一个脚本,该脚本将部署“x”个公共 IP,并将它们关联到资源组中的相应防火墙。
我能够使用复制循环成功完成公共 IP 的部署。
但是,我无法将那些生成的 pips associated 到资源组中的相应防火墙。
Deployment template language expression evaluation failed: 'The template language function 'copyIndex' has an invalid argument. The provided copy name '' doesn't exist in the resource.
我尝试了以下代码,但它产生了上述错误(我的代码的语法/逻辑可能是问题所在——我对使用 Azure 比较陌生,但仍然不太习惯复制循环)。
"ipConfigurations": [
{
"name": "fwIP",
"properties": {
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', variables('firewallPublicIpName'))]"
},
"subnet": {
"id": "[resourceId(resourceGroup().name,'Microsoft.Network/virtualNetworks/subnets',variables('vnetName'),'AzureFirewallSubnet')]"
}
},
"copy":[
{
"name":"publicIPAddress",
"count":"[parameters('NumberOfFwPIPs')]",
"input":{
"publicIPAddress":{
"id": "[concat(resourceId('Microsoft.Network/publicIPAddresses', variables('FirewallPublicIpExtraName'),copyIndex(5)))]"
}
}
}
]
}
],
感谢对此的任何想法或建议。
我已经使用
Microsoft-Doc使用复制循环部署了
Ip address prefix
。
打开Azure门户并搜索部署自定义模板并使用以下代码使用复制循环部署IP地址前缀。
使用下面的示例 Arm 模板作为示例。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminUsername": {
"type": "String",
"metadata": {
"description": "Admin username for the backend servers"
}
},
"adminPassword": {
"type": "SecureString",
"metadata": {
"description": "Password for the admin account on the backend servers"
}
},
"location": {
"defaultValue": "[resourceGroup().location]",
"type": "String",
"metadata": {
"description": "Location for all resources."
}
},
"vmSize": {
"defaultValue": "Standard_B2ms",
"type": "String",
"metadata": {
"description": "Size of the virtual machine."
}
}
},
"variables": {
"copy": [
{
"name": "azureFirewallIpConfigurations",
"count": "[length(range(0, 2))]",
"input": {
"name": "[format('IpConf{0}', add(range(0, 2)[copyIndex('azureFirewallIpConfigurations')], 1))]",
"properties": {
"subnet": "[if(equals(range(0, 2)[copyIndex('azureFirewallIpConfigurations')], 0), json(format('{{\"id\": \"{0}\"}}', variables('azureFirewallSubnetId'))), json('null'))]",
"publicIPAddress": {
"id": "[resourceId('Microsoft.Network/publicIPAddresses', format('{0}{1}', variables('publicIpAddressName'), add(range(0, 2)[range(0, 2)[copyIndex('azureFirewallIpConfigurations')]], 1)))]"
}
}
}
}
],
"virtualMachineName": "myVM",
"virtualNetworkName": "myVNet",
"networkInterfaceName": "net-int",
"ipConfigName": "ipconfig",
"ipPrefixName": "public_ip_prefix",
"ipPrefixSize": 31,
"publicIpAddressName": "public_ip",
"nsgName": "vm-nsg",
"firewallName": "FW-01",
"vnetPrefix": "10.0.0.0/16",
"fwSubnetPrefix": "10.0.0.0/24",
"backendSubnetPrefix": "10.0.1.0/24",
"azureFirewallSubnetId": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('virtualNetworkName'), 'AzureFirewallSubnet')]"
},
"resources": [
{
"type": "Microsoft.Network/publicIPPrefixes",
"apiVersion": "2022-01-01",
"name": "[variables('ipPrefixName')]",
"location": "[parameters('location')]",
"sku": {
"name": "Standard"
},
"properties": {
"prefixLength": "[variables('ipPrefixSize')]",
"publicIPAddressVersion": "IPv4"
}
},
{
"type": "Microsoft.Network/publicIPAddresses",
"apiVersion": "2022-01-01",
"name": "[format('{0}{1}', variables('publicIpAddressName'), add(range(0, 2)[copyIndex()], 1))]",
"location": "[parameters('location')]",
"dependsOn": [
"[resourceId('Microsoft.Network/publicIPPrefixes', variables('ipPrefixName'))]"
],
"sku": {
"name": "Standard"
},
"properties": {
"publicIPAddressVersion": "IPv4",
"publicIPAllocationMethod": "Static",
"publicIPPrefix": {
"id": "[resourceId('Microsoft.Network/publicIPPrefixes', variables('ipPrefixName'))]"
},
"idleTimeoutInMinutes": 4
},
"copy": {
"name": "publicIPAddress",
"count": "[length(range(0, 2))]"
}
}
]
}