gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-05 02:18:21 24 4
gpt4 key购买 nike

创建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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com