gpt4 book ai didi

azure - 复制存储帐户并输出连接字符串

转载 作者:行者123 更新时间:2023-12-01 00:26:09 24 4
gpt4 key购买 nike

我需要部署 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": {}
}

现在的问题是,没有有关如何迭代存储帐户以输出连接字符串的信息。有人做过这样的事吗?如何迭代已部署的存储帐户并输出连接字符串?

最佳答案

这是一个根据上面的示例模板修改的工作 ARM 模板。

它能够在部署输出中输出通过 ARM 模板部署部署的部分存储帐户连接字符串列表,没有存储帐户 key

这是由于一个 Unresolved 已知问题造成的:listKeys not supported in variable #1503在 ARM 中,不允许在 ARM 模板变量中使用列出存储帐户 key 的 listKeys

输出:

{ "connectionstrings": [ { "connectionstring": "DefaultEndpointsProtocol=https;AccountName=0storageojjbpuu4wl6r4;AccountKey=" }, { "connectionstring": "DefaultEndpointsProtocol=https;AccountName=1storageojjbpuu4wl6r4;AccountKey=" }, { "connectionstring": "DefaultEndpointsProtocol=https;AccountName=2storageojjbpuu4wl6r4;AccountKey=" } ] }

{
"$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')]"
}
}
}

关于azure - 复制存储帐户并输出连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48756953/

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