[英]Multiple IP address variable in Azure ARM Template
如果我使用 ARM 模板在 Azure 中创建 IP 组并希望添加多个 IP 地址作为参数而不是将它们放入资源主体中,这可能吗?
模板如下
{
"type": "Microsoft.Network/ipGroups",
"apiVersion": "2021-05-01",
"name": "string",
"location": "string",
"tags": {
"tagName1": "tagValue1",
"tagName2": "tagValue2"
},
"properties": {
"ipAddresses": [ "10.10.10.10",
"10.10.10.11" ]
}
}
如果我创建如下所示的参数
"ipgipaddress": {
"type": "string
"Value":
"10.10.10.10",
"10.10.10.11"
}
并将代码更新为
{
"type": "Microsoft.Network/ipGroups",
"apiVersion": "2021-05-01",
"name": "string",
"location": "string",
"tags": {
"tagName1": "tagValue1",
"tagName2": "tagValue2"
},
"properties": {
"ipAddresses": "[parameters('ipgroupsettings')]"
}
}
想要添加多个 IP 地址作为参数,而不是将它们放在资源主体中,这可能吗?
是的,有可能,您可以添加多个 IP 地址作为参数。 根据文档,属性ipAddresses
是字符串数组类型。
为了重现这一点,在我们的 ARM 模板中,我们将这些ipaddresses
初始化为数组类型的参数,并使用"[paramerter(ipaddresses)]"
进一步传递这些值。
我们对此进行了测试,它工作正常。
这是 ARM 模板:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ipaddress":{
"type": "array",
"defaultValue": ["10.0.1.0/27","10.0.2.0/27"]
}
},
"functions": [],
"variables": {},
"resources": [{
"type": "Microsoft.Network/ipGroups",
"apiVersion": "2020-11-01",
"name": "testipgroups",
"location":"[resourceGroup().location]",
"properties":{
"ipAddresses": "[parameters('ipaddress')]"
}
}
],
"outputs": {}
}
以下是样品 Output 供参考:
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ipaddress":{
"type": "string",
"defaultValue": "10.0.1.0/27,10.0.2.0/27"
}
},
"functions": [],
"variables": {
"iparray": "[split(parameters('ipaddress'),',')]"
},
"resources": [{
"type": "Microsoft.Network/ipGroups",
"apiVersion": "2020-11-01",
"name": "testipgroups",
"location":"[resourceGroup().location]",
"properties":{
"ipAddresses": "[variables('iparray')]"
}
}
],
"outputs": {}
}
如果您想节省时间以不带太多双引号 (" ") 的字符串形式提供输入,请使用拆分函数并删除定界符(上例中的逗号),这将创建一个 IP 数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.