gpt4 book ai didi

azure - 在本例中输出 Bicep 中的数组是正确的方法吗?

转载 作者:行者123 更新时间:2023-12-03 03:22:46 25 4
gpt4 key购买 nike

嗨,看看最后一行。这是输出数组的可接受的方式吗?或者有更好的方法吗?

@description('This is the location which needs to be provided, this is the Azure region')
param location string = resourceGroup().location

var storageAccountSku = 'standard_LRS'

resource storageAccounts 'Microsoft.Storage/storageAccounts@2022-09-01' = [for i in range(0, 4): {
name: '${i}mystorage1234'
location: location
sku: {
name: storageAccountSku
}
kind: 'StorageV2'
}]

output storageNames array = [for i in range(0,4) : storageAccounts[i].name]

提前谢谢您,

杰森

PS:我尝试在 Microsoft 页面上寻找答案,但没有看到

最佳答案

Is this an acceptable way of outputting the array? Or is there a better way?

是的,可以提取 storageAccounts 数组中每个对象的 name 属性,并以在最后一行导出数组的方式使用这些值生成一个新数组。

我尝试使用相同的二头肌代码添加 id 属性,并得到了异常(exception)的结果:

test.bicep

@description('This is the location which needs to be provided, this is the Azure region')
param location string = resourceGroup().location

var storageAccountSku = 'standard_LRS'

resource storageAccounts 'Microsoft.Storage/storageAccounts@2022-09-01' = [for i in range(0, 4): {
name: '${i}venkat123'
location: location
sku: {
name: storageAccountSku
}
kind: 'StorageV2'
}]

output storageNames array = [for i in range(0,4) : {
Name:storageAccounts[i].name
Id:storageAccounts[i].id}]

使用以下命令部署:

 az deployment group create --resource-group <Your-resource-group> --template-file test.bicep

输出:

"outputs": {
"storageNames": {
"type": "Array",
"value": [
{
"Id": "/subscriptions/subid/resourceGroups/xxxx/providers/Microsoft.Storage/storageAccounts/0venkat123",
"Name": "0venkat123"
},
{
"Id": "/subscriptions/xxxx/resourceGroups/xxxx/providers/Microsoft.Storage/storageAccounts/1venkat123",
"Name": "1venkat123"
},
{
"Id": "/subscriptions/xxxxx/resourceGroups/v-venkat-mindtree/providers/Microsoft.Storage/storageAccounts/2venkat123",
"Name": "2venkat123"
},
{
"Id": "/subscriptions/xxxxx/resourceGroups/xxxx/providers/Microsoft.Storage/storageAccounts/3venkat123",
"Name": "3venkat123"
}
]
}
}

enter image description here

门户: enter image description here

关于azure - 在本例中输出 Bicep 中的数组是正确的方法吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76512208/

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