azure - ARM 模板: concatenate each element of an array with constant value

标签 azure azure-resource-manager azure-rm-template

创建arm模板时是否可以将数组的每个元素与常量字符串连接起来?下面是我创建的参数和我尝试创建的资源。

  "parameters": {

    "servicesNames": {
      "type": "array",
      "defaultValue": [
        "test-api-content",
        "test-svc-content"
      ]
    }
  }

    {
      "apiVersion": "2016-03-30",
      "type": "Microsoft.Network/publicIPAddresses",
      "name": "[concat(parameters('servicesNames'),'pip')]",
      "location": "[resourceGroup().location]",
      "copy": {
        "name": "PIPaddresscopy",
        "count": "[length(parameters('servicesNames'))]"
      },
      "tags": {
        "displayName": "PublicIPAddress"
      }
   }

我希望使用

创建资源名称的输出

"test-api-contentpip"

我如何收到以下错误

The provided parameters for language function 'concat' are invalid. Either all or none of the parameters must be an array

请建议我如何连接元素的每个值

最佳答案

只是添加到现有答案(因为我认为它有点不清楚)。

您想要对代码执行的操作 - 将数组与字符串连接起来,而您需要做的是将数组的每个元素与字符串连接起来。

有一个 copyIndex() 函数表示循环的当前迭代。您可以使用 array[number] 来访问数组的特定成员。所以

parameters('servicesNames')[copyIndex()]

在您的情况下表示 parameters('servicesNames')[0]parameters('servicesNames')[1] 。这实际上意味着您已经迭代了这个数组。

关于azure - ARM 模板: concatenate each element of an array with constant value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45528749/

相关文章:

azure - Azure Maps 是否将图像叠加层发送到云?

Azure API 管理多区域部署和多个区域的后端服务

azure - 从二头肌循环中调用的模块获取输出

azure - 如何使 Azure Function 代码在 Azure ARM json 模板中可读

azure - 将状态保留到 Azure Service Fabric 中的附加磁盘

azure - 如何使用 ARM 模板为注释创建 Application Insights API key

c# - 什么是 ServiceObjectiveId?

api - IBM Bluemix 和 Azure 是否为 API Blueprint 和 OpenAPI 提供同等支持?描述 API

image - Azure VM 自定义操作系统镜像 ARM 模板部署

azure - 更新现有 Azure Service Fabric 群集的 WadCfg "only"?