如何在ARM模板中引用静态IP地址?

How to reference static IP address in ARM template?

我在资源组中有 public 个名称为 'VPNPublicIP' 的静态 IP 地址。如何在下面的 ARM 模板中引用这个地址?我不想改变这个静态

 "resources": [
{
      "apiVersion": "[variables('apiVersion')]",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[variables('WebPublicIPName')]",
      "location": "[variables('location')]",
      "properties": {
        "privateIPAllocationMethod": "Static",
        "publicIPAddress": "VPNPublicIP",

      }
    }
}

我认为上面的不对,请指教

您可以将现有 public IP 引用到另一个资源,其资源 ID 为:

"publicIPAddress": {
       "id":"[resourceId('Microsoft.Network/publicIPAddresses',variables('publicIPAddressName'))]"
 },

您不必在同一资源中引用它,只需将其 privateIPAllocationMethod 属性 设置为静态即可。它将被创建为静态 IP 地址。

{
    "apiVersion": "[variables('apiVersion')]",
    "type": "Microsoft.Network/publicIPAddresses",
    "name": "[variables('WebPublicIPName')]",
    "location": "[variables('location')]",
    "properties": {
        "privateIPAllocationMethod": "Static"
    }
}

如果你想将它附加到某个东西上,你可以使用 resourceId() 功能,正如其他答案所建议的那样。