azure 如何在ARM脚本中使用复制循环进行防火墙公有IP关联

vsnjm48y  于 2023-03-09  发布在  其他
关注(0)|答案(1)|浏览(65)

我目前正在编写一个脚本,它将部署“x”个公共IP,并将它们与资源组中的相应防火墙关联。
我能够使用复制循环成功地完成公共IP的部署。
但是,我无法将这些生成的pips关联到资源组中的相应防火墙。

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

          }
        ]
      }
      
    ],

感谢任何关于这方面的想法或建议。

rta7y2nd

rta7y2nd1#

  • 我已经使用拷贝循环和Microsoft-Doc部署了Ip address prefix
  • 打开Azure门户并搜索部署自定义模板,然后使用以下代码通过复制循环部署IP地址前缀。
  • 使用以下样本臂模板作为示例。
{
    "$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))]"
      }
    }
  ]
}
  • 成功部署后,打开Azure门户-〉转到资源组,如下所示。

相关问题