首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何在if语句中使用use reference resource函数

如何在if语句中使用use reference resource函数
EN

Stack Overflow用户
提问于 2019-02-06 17:53:04
回答 1查看 108关注 0票数 0

我正在尝试使用引用发送私有if (concat(variables(‘nicName’),0)).ipConfigurations.properties.privateIPAddress到客户扩展),如果vm的数量是3,那么3个私有if应该传递给客户扩展,如果vm的数量是5,那么5个私有if应该传递给客户扩展。我定义了两个扩展,但它正在寻找依赖。

代码语言:javascript
运行
复制
  "resources": [
    {
      "condition": "[equals(variables('numberOfVM'), 3)]",
      "name": "config-app-3",
      "type": "extensions",
      "location": "[parameters('location')]",
      "apiVersion": "2015-06-15",
      "dependsOn": [
          "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 0))]",
          "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 1))]",
          "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 2))]"
       ],
      "tags": {
        "displayName": "config-app"
      },
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "protectedSettings": {
          "commandToExecute": "[concat('sh /home/centos/install_apache.sh \',' ','--ip-address \' ,reference(concat(variables('nicName'), 0)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 1)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 2)).ipConfigurations[0].properties.privateIPAddress)]"
        }
      }
    },
    {
      "condition": "[equals(variables('numberOfVM'), 5)]",
      "name": "config-app-5",
      "type": "extensions",
      "location": "[parameters('location')]",
      "apiVersion": "2015-06-15",
      "dependsOn": [
         "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 0))]",
         "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 1))]",
         "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 2))]",
         "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 3))]",
         "[concat('Microsoft.Compute/virtualMachines/', concat(parameters('vmName'), 4))]",
       ],
      "tags": {
        "displayName": "config-app"
      },
      "properties": {
        "publisher": "Microsoft.Azure.Extensions",
        "type": "CustomScript",
        "typeHandlerVersion": "2.0",
        "autoUpgradeMinorVersion": true,
        "protectedSettings": {
          "commandToExecute": "[concat('sh /home/centos/install_apache.sh \',' ','--ip-address \' , reference(concat(variables('nicName'), 0)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 1)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 2)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 3)).ipConfigurations[0].properties.privateIPAddress,' ', reference(concat(variables('nicName'), 4)).ipConfigurations[0].properties.privateIPAddress)]"
        }
      }
    }
  ]

我在部署模板时遇到下面的错误。‘模板引用'vm-nic-3’无效:找不到具有此名称的模板资源或资源副本。有关用法的详细信息,请参阅https://aka.ms/arm-template-expressions/#reference。所以我尝试定义一个客户扩展来处理这两种情况。

EN

回答 1

Stack Overflow用户

发布于 2019-02-06 18:15:13

您可以使用if()函数来选通它们:

代码语言:javascript
运行
复制
if(equals(variables('numberOfVM'), 5), reference(concat(variables('nicName'), 3)).ipConfigurations[0].properties.privateIPAddress, '')

对于所有引用函数的出现,您都需要重复此操作

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/54550708

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档