如何在ARM模板中替换最后一个八位字节的IP地址

时间:2018-04-10 07:33:16

标签: azure arm-template vnet

我正在尝试在ARM模板中传递带有IP地址前缀(例如,10.0.0.0 / 24)的参数来部署VNET

在ARM模板中,我想将10.0.0.0/24替换为10.0.0.123,并将其分配给我希望稍后用于创建VM的NIC。

我希望有没有办法使用ARM模板实现这一目标?

3 个答案:

答案 0 :(得分:1)

嗯,没有办法做到这一点,最简单的方法:

"var1": "[first(split(parameters('addressPrefix'), '/'))]",
"var2": "[substring(variables('var1'), 0, sub(length(variables('var1'), 1)))]"
"var3": "[concat(variables('var2'), 'ipgoeshere')]"

或者你可以删除最后4个字符并连接ip地址,或者将部分拆分成ip地址:

"var1": "[first(split(parameters('addressPrefix'), '/'))]",
"var2": "[concat(variables('var1')[0], '.', variables('var1')[1], '.', variables('var1')[2], '.ipgoeshere')]"

答案 1 :(得分:0)

您可以使用"privateIPAllocationMethod": "Static"并指定私有IP地址,如下所示:

"ipConfigurations": [
          {
            "name": "ipconfig1",
            "properties": {
              "privateIPAllocationMethod": "Static",
              "privateIPAddress": "[parameters('privateIPAddress')]",
              "publicIPAddress": {
                "id": "[resourceId('Microsoft.Network/publicIPAddresses',parameters('publicIPAddressName'))]"
              },
              "subnet": {
                "id": "[parameters('subnetRef')]"
              }
            }
          }
        ]

这里有关于静态私有IP地址的示例template,请参阅它。

答案 2 :(得分:0)

我就是这样做的

"variables" : {
    "subnetAddress" : "[first(split(parameters('subnetAddressWithMask'), '/'))]",
    "subnetOctets3" : "[take(split(variables('subnetAddress'), '.'), 3)]",
    "subnetNetwork" : "[concat(variables('subnetOctets3')[0], '.', variables('subnetOctets3')[1], '.', variables('subnetOctets3')[2])]"
  },
  "outputs": {
    "subnetAddress" : {
    "type": "string",
    "value" : "[variables('subnetAddress')]"
    },
    "subnetOctets3" : 
    {

    "type": "array",
    "value" :  "[variables('subnetOctets3')]"
    }
   ,
    "subnetNetwork" : {
"type" : "string",
"value" :     "[variables('subnetNetwork')]"

    }

带输出

  "Outputs": {
    "deploymentAppGw": {
      "Type": "Object",
      "Value": {
        "subnetAddress": {
          "type": "String",
          "value": "10.0.0.0"
        },
        "subnetOctets3": {
          "type": "Array",
          "value": [
            "10",
            "0",
            "0"
          ]
        },
        "subnetNetwork": {
          "type": "String",
          "value": "10.0.0"
        }
      }
    }
  },

后来我以这种方式使用它:"[concat(variables('subnetNetwork'), '.', copyIndex(10))]" 或类似的方式。