azure - 是否有一种解决方法可以让 Azure ARM 模板复制块接受零长度数组?
问题描述
我正在开发一个 Azure ARM 模板,该模板将有一个字符串参数,需要一个以逗号分隔的电子邮件地址列表。在模板中,我想解析它并复制到资源类型emailReceivers
属性所需的对象类型数组中。Microsoft.Insights/ActionGroups
输入必须是单个字符串,因为该值将被 Octopus Deploy 替换为我们部署管道的一部分。
只要提供至少一个电子邮件地址,我的模板就可以正常工作,但我希望这个值是可选的。不幸的是,当提供空字符串时,我收到以下错误:
'0' 行和 '0' 列的模板 'copy' 定义具有无效的副本计数。复制计数必须是正整数值并且不能超过“800”。
显然,这些复制块不支持零长度数组,所以我想知道是否有人知道一种解决方法或狡猾的黑客可以让我实现我想要的。
这是一个精简的模板示例:
{
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"emailAddresses": {
"type": "string",
"defaultValue": "one@email.com, two@email.com",
"metadata": {
"description": "Comma-separated list of email recipients."
}
}
},
"variables": {
"emailArray": "[if(equals(length(parameters('emailAddresses')), 0), json('[]'), split(parameters('emailAddresses'),','))]",
"copy": [
{
"name": "emailReceivers",
"count": "[length(variables('emailArray'))]",
"input": {
"name": "[concat('Email ', trim(variables('emailArray')[copyIndex('emailReceivers')]))]",
"emailAddress": "[trim(variables('emailArray')[copyIndex('emailReceivers')])]"
}
}
]
},
"resources": [],
"outputs": {
"return": {
"type": "array",
"value": "[variables('emailReceivers')]"
}
}
}
解决方案
好吧,不是直接的,但你可以这样做:
"copy": [
{
"name": "emailReceivers",
"count": "[if(equals(length(variables('emailArray')), 0), 1, length(variables('emailArray')))]",
"input": {
"name": "[concat('Email ', trim(variables('emailArray')[copyIndex('emailReceivers')]))]",
"emailAddress": "[trim(variables('emailArray')[copyIndex('emailReceivers')])]" << these need the same if to put placeholder value inside
}
}
]
然后,如果长度等于 0 bla-bla-bla,您将在某处实现条件
推荐阅读
- django-models - 从 Django 中的 3rd 方库更改模型字段
- coq - 如何在 coq 中证明 n <= n + S m?
- python - 如何按样本加快 pandas 分组?
- azure - 如何通过 curl 生成存储帐户 SAS 令牌
- ruby-on-rails - Ruby on Rails 验证其他列存在的唯一性
- camera - USB HOST UVC 相机 FTDI Vinculum-II 不读取视频流
- flutter - M1 MacBook Pro Flutter App:命令 PhaseScriptExecution 失败,退出代码为非零
- python-3.x - 使用范围创建的 Sympy 调用符号
- python - 从字典创建列表列表
- python - 如何了解 python 多处理上的活跃工作者