我尝试最大程度地减少手臂模板,但我在这里陷入困境...
我的原始模板是:
"parameters": {
"subscriptionId": {
"type": "String"
},
"resourcegroupName": {
"type": "String"
},
.....
"databases": {
"type": "Array"
},
"failoverPolicy": {
"type": "String"
}
},
"variables": {},
"resources": [
{
"type": "Microsoft.Sql/servers/failoverGroups",
"name": "[concat(parameters('primaryServer'), '/', parameters('failovergroupName'))]",
"apiVersion": "2015-05-01-preview",
"location": "eastus",
"properties": {
"readWriteEndpoint": {
"failoverPolicy": "[parameters('failoverPolicy')]"
},
"partnerServers": [
{
"id": "[concat('/subscriptions/',parameters('subscriptionId'),'/resourceGroups/',parameters('resourcegroupName'),'/providers/Microsoft.Sql/servers/',parameters('partnerServer'))]"
}
],
"databases": "[parameters('databases')]"
},
"dependsOn": [
"[concat('Microsoft.Sql/servers/',parameters('partnerServer'))]",
"[concat('Microsoft.Sql/servers/',parameters('partnerServer'),'/elasticPools/',parameters('primaryElasticPoolName'))]"
]
},
....
和我的参数文件包含:
"parameters": {
"subscriptionId": {
"value": "11111-4444-5555-666-777777777"
},
"resourcegroupName": {
"type": "RG-ElasticPool"
},
"primaryElasticPoolName": {
"value": "crelasticpool01"
},
....
"databases": {
"value": [
"/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb03",
"/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb02",
"/subscriptions/11111-4444-5555-666-777777777/resourceGroups/RG-ElasticPool/providers/Microsoft.Sql/servers/crelasticsrv01/databases/crelasticdb01"
]
},
"failoverPolicy": {
"value": "Manual"
}
}
我只能拥有:
"databases": {
"value": [
"crelasticdb03",
"crelasticdb02",
"crelasticdb01"
]
在我的参数文件中而不是长ID中,并在我的模板文件中conctt long ID
我尝试使用多个配置,例如:
"databases": "[concat('/subscriptions/',parameters('subscriptionId'),'/resourceGroups/',parameters('resourcegroupName'),'/providers/Microsoft.Sql/servers/',parameters('primaryServer'),'/databases/',parameters('databases')[copyIndex()])]"
但是我总是会遇到相对于CopyIndex的部署错误...
不幸的是,您不能使用复制函数来创建数组。您只能使用它创建一系列对象。您似乎需要一个字符串,这是不可能的。
您可以使用嵌套模板和循环工作,但是只需使用您拥有的东西,它就更容易清洁。