gpt4 book ai didi

azure 二头肌 : for-loop in variable definition not possible?

转载 作者:行者123 更新时间:2023-12-03 02:14:15 26 4
gpt4 key购买 nike

我正在创建一个像这样的二头肌模块:

param permission object

var keys = [for key in permission.keys: key]
var secretes= [for secret in permission.secrets: secret]
var certificates = [for certificate in permission.certificates: certificate]

其中“permissions”是包含这 3 个数组的对象。
这很好用,但我更喜欢这样的东西(一个复杂的变量而不是 3 个单独的数组):

var x = {
keys: [for key in permission.keys: key]
secrets: [for secret in permission.secrets: secret]
certificates: [for certificate in permission.certificates: certificate]
}

从语法上讲,这是不允许的。有趣的是,当在资源定义中执行相同的操作时,相同的语法是有效的,例如:

resource EventHubAuthorization 'Microsoft.EventHub/namespaces/eventhubs/authorizationRules@2021-01-01-preview' = {
name: '${EventHub.name}/${AuthorizationName}'
properties: {
rights: [for right in Rights: right]
}
}

事情就是这样,还是我错过了一些东西,而我想要的东西可以完成 - 只是不同?

br 沃尔克

最佳答案

根据错误消息,不支持此功能:

For-expressions are not supported in this context. For-expressions may be used as values of resource, module, variable, and output declarations, or values of resource and module properties.bicep(BCP138)

你总是可以做这样的事情:

param permission object

var keys = [for key in permission.keys: key]
var secrets= [for secret in permission.secrets: secret]
var certificates = [for certificate in permission.certificates: certificate]

var x = {
keys: keys
secrets: secrets
certificates: certificates
}

但是这里的x变量看起来或多或少与permission参数相同。

关于 azure 二头肌 : for-loop in variable definition not possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71979177/

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