无法从通知中心通过listkeys错误BCP182获取连接字符串。

huangapple go评论83阅读模式
英文:

Bicep - Can't get connection string from Notification hub through listkeys Error BCP182

问题

我试图获取通知中心连接字符串的数组,但总是从listKeys表达式中收到错误消息。

BCP182: 此表达式正在用于“notificationHubConfig”变量的for-body中,该变量需要在部署开始时计算的值

这是我的代码。首先,在我的环境yaml文件中,我有一个名为notificationHubs的数组

notificationhubs:
'["tenantId1:nameSpaceNotificationHub1:Hubname1","tenantId2:nameSpaceNotificationHub2:Hubname2"]'

在bicep模块文件中,首先我获取通知中心的命名空间。它们都是现有资源。然后,我通过listKeys函数创建通知中心连接字符串的数组。错误发生在listKeys表达式中。

resource namespace 'Microsoft.NotificationHubs/namespaces@2017-04-01' existing = [for i in range(0, length(notificationhubs)): {
  name: '${split(notificationhubs[i], ':')[1]}'
  scope: resourceGroup('${notificationHubResourceGroupName}')
}]

var notificationHubConfig = [for i in range(0, length(notificationhubs)): {
  name: notificationhubs[i]
  value: '${listKeys('${namespace[i].id}/AuthorizationRules/RootManageSharedAccessKey', namespace[i].apiVersion).primaryConnectionString}'
}]

我已经测试了表达式的所有输入,它们似乎都是正确的(例如namespace[i].id,namespace[i].apiVersion等)。是否有人可以提供帮助?非常感谢。

英文:

I am trying to get an array of Notification hub connection strings however I always got an error message from listKeys expression

> BCP182: : This expression is being used in the for-body of the
> variable "notificationHubConfig", which requires values that can be
> calculated at the start of the deployment

Here is my code. First I have an array call notificationHubs in my environment yaml file

notificationhubs:
'["tenantId1:nameSpaceNotificationHub1:Hubname1","tenantId2:nameSpaceNotificationHub2:Hubname2"]'

In module bicep file. First I get the namespaces of Notification Hubs. They are all existing resource. Then I create an array of notifition hub connection string through listKeys function. And the error happen due to the listKeys expression.

resource namespace 'Microsoft.NotificationHubs/namespaces@2017-04-01' existing = [for i in range(0, length(notificationhubs)): {
  name: '${split(notificationhubs[i], ':')[1]}'
  scope: resourceGroup('${notificationHubResourceGroupName}')
}]

var notificationHubConfig = [for i in range(0, length(notificationhubs)): {
  name: notificationhubs[i]
  value: '${listKeys('${namespace[i].id}/AuthorizationRules/RootManageSharedAccessKey', namespace[i].apiVersion).primaryConnectionString}'
}]

I have tested all the inputs of the expression and it seem correct (for example namespace[i].id, namespace[i].apiVersion ...etc). Could anyone can help please. Thank you in advance

答案1

得分: 0

The bicep logic that replaces variables in your case does not work for loops.

There is an open issue it on GitHub: Variable substitution logic does not work for variables with loop expressions

英文:

The bicep logic that replaces variables in your case does not work for loops.

There is an open issue it on GitHub: Variable substitution logic does not work for variables with loop expressions

huangapple
  • 本文由 发表于 2023年2月6日 20:19:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75361235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定