azure bicep:变量定义中的for循环不可能吗?

azure bicep: for-loop in variable definition not possible?

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

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]

其中“权限”是包含这 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 参数差不多。