我需要部署N个存储帐户并输出连接字符串作为数组或更好的逗号分隔统一字符串值。我发现了一个非常有用的article如何部署多个资源。以下是我可以创建多个存储帐户的方法。
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"resources": [
{
"apiVersion": "2016-01-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[concat(copyIndex(),'storage', uniqueString(resourceGroup().id))]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"properties": {},
"copy": {
"name": "storagecopy",
"count": 3
}
}
],
"outputs": {}
}
现在问题是,没有关于如何迭代存储帐户以输出连接字符串的信息。有人做过这样的事吗?如何迭代已部署的存储帐户并输出连接字符串?
答案 0 :(得分:4)
这是一个基于上面的示例模板修改的ARM模板。
能够在部署输出中输出通过ARM模板部署部署的部分存储帐户连接字符串列表,不使用存储帐户密钥。
这是由于一个开放且已知的问题:ARM中的listKeys not supported in variable #1503,其中列出存储帐户密钥的 listKeys 不允许在ARM模板变量中使用。< / p>
输出:
{&#34; connectionstrings&#34;:[ { &#34; connectionstring&#34;:&#34; DefaultEndpointsProtocol = https; AccountName = 0storageojjbpuu4wl6r4; AccountKey =&#34; }, { &#34; connectionstring&#34;:&#34; DefaultEndpointsProtocol = https; AccountName = 1storageojjbpuu4wl6r4; AccountKey =&#34; }, { &#34; connectionstring&#34;:&#34; DefaultEndpointsProtocol = https; AccountName = 2storageojjbpuu4wl6r4; AccountKey =&#34; }]}
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"storageAccountCount": {
"type": "int",
"defaultValue": 3
}
},
"variables": {
"storageAccountConnectionStrings": {
"copy": [
{
"name": "connectionstrings",
"count": "[parameters('storageAccountCount')]",
"input": {
"connectionstring": "[concat('DefaultEndpointsProtocol=https;AccountName=', concat(copyIndex('connectionstrings'),'storage', uniqueString(resourceGroup().id)), ';AccountKey=')]"
}
}
]
}
},
"resources": [
{
"apiVersion": "2016-01-01",
"type": "Microsoft.Storage/storageAccounts",
"name": "[concat(copyIndex(),'storage', uniqueString(resourceGroup().id))]",
"location": "[resourceGroup().location]",
"sku": {
"name": "Standard_LRS"
},
"kind": "Storage",
"copy": {
"name": "storagecopy",
"count": "[parameters('storageAccountCount')]"
}
}
],
"outputs": {
"connectionStringsArray": {
"type": "object",
"value": "[variables('storageAccountConnectionStrings')]"
}
}
}
答案 1 :(得分:3)
有几个选择:
Dim Frm1 As Form1
Frm1 = New Form1
Frm1.ComboBox1.Items.Add("Test")
部分内的副本创建带副本的变量。但是我建议你退后一步,实际上,大部分时间从ARM模板输出任何内容都是浪费精力,因为这些信息可以用PowerShell或azure cli轻松挽救,而且耗费更少。