ARM - 获取 VMSS 的私有 IP

ARM - get VMSS's private IPs

我有一个使用 ARM 模板部署的 VMSS。

我想将它的第一个 VM 的 IP 地址添加到 output

在 Azure 资源浏览器中 - 我将资源视为:

...
        "ipConfigurations": [
          {
            "name": "jm-website-script-4-master-ip",
            "id": "/subscriptions/0a4f2b9c-***-40b17ef8c3ab/resourceGroups/jm-website-script-4/providers/Microsoft.Compute/virtualMachineScaleSets/jm-website-script-4-master-vmss/virtualMachines/1/networkInterfaces/jm-website-script-4-master-nic/ipConfigurations/jm-website-script-4-master-ip",
            "etag": "W/\"09be80d2-76f5-49fc-ad47-0ef836a3799a\"",
            "properties": {
              "provisioningState": "Succeeded",
              "privateIPAddress": "10.0.0.5",
...

所以我尝试添加到 variables:

"masterVM": "[concat('Microsoft.Compute/virtualMachineScaleSets/jm-website-script-4-master-vmss/virtualMachines/1/networkInterfaces/jm-website-script-4-master-nic/ipConfigurations/jm-website-script-4-master-ip')]",

然后调用输出:

  "outputs": {
    "MasterFirstIPConfig": {
      "type": "string",
      "value": "[reference(variables('masterVM').properties.privateIPAddress)]"
    }
  }

哪个returns我有一个错误:

The language expression property 'Microsoft.WindowsAzure.ResourceStack.Frontdoor.Expression.Expressions.JTokenExpression' can't be evaluated..

我想我的 masterVM 变量定义完全有问题,但无法理解。

UPD 解决方案

感谢 4c74356b41 的回答。

解决方案如下所示:

变量定义:

"masterVM": "Microsoft.Compute/virtualMachineScaleSets/jm-website-script-4-master-vmss/virtualMachines/1/networkInterfaces/jm-website-script-4-master-nic"

输出:

  "outputs": {
   "MasterFirstIPConfig": {
     "type": "string",
     "value": "[reference(variables('masterVM'),'2016-09-01').ipConfigurations[0].properties.privateIPAddress]"
   }
 }

嗯,您定位的资源不对。你应该以 networkInterface 为目标(在这种情况下你不需要连接),你还必须正确引用它:

"masterVM": "Microsoft.Compute/virtualMachineScaleSets/jm-website-script-4-master-vmss/virtualMachines/1/networkInterfaces/jm-website-script-4-master-nic]"

然后像这样引用

"value": "[reference(variables('masterVM'),'2016-09-01').ipConfigurations[0].properties.privateIPAddress]"