gpt4 book ai didi

Azure 应用程序配置存储 - 使用 Bicep 设置键值标签

转载 作者:行者123 更新时间:2023-12-05 03:27:32 26 4
gpt4 key购买 nike

我正在尝试使用 Bicep 将值添加到 Azure 应用程序配置存储。我在向 keyValue 添加标签时遇到问题。

这是我的模块:

@description('Configuration Store Name')
param configurationStoreName string

@description('key prefix')
param prefix string

@description('key name')
param keyName string

@description('value')
param value string

@description('content type')
param contentType string = 'string'

@description('Deployment Environment')
param deploymentEnvironment string = 'dev'

resource configurationStore 'Microsoft.AppConfiguration/configurationStores@2021-10-01- preview' existing = {
name: configurationStoreName
}

resource configurationStoreValue 'Microsoft.AppConfiguration/configurationStores/keyValues@2021-10-01-preview' = {
name: '${prefix}:${keyName}'
parent: configurationStore
properties: {
contentType: contentType
value: value
tags: {
environment: deploymentEnvironment
}
}
}

似乎没有任何方法可以添加标签,而我想这样做来启用过滤。

可以在使用 Azure 门户创建 KeyValue 时完成此操作,因此应该可以使用 Bicep。

我错过了什么,还是 Bicep 缺少这个功能?

最佳答案

编辑 2022 年 4 月documentation现已更新

The keyValues resource's name is a combination of key and label. The key and label are joined by the $ delimiter. The label is optional. In the above example, the keyValues resource with name myKey creates a key-value without a label.

Percent-encoding, also known as URL encoding, allows keys or labels to include characters that are not allowed in ARM template resource names. % is not an allowed character either, so ~ is used in its place. To correctly encode a name, follow these steps:

  1. Apply URL encoding
  2. Replace ~ with ~7E
  3. Replace % with ~

For example, to create a key-value pair with key name AppName:DbEndpoint and label name Test, the resource name should be AppName~3ADbEndpoint$Test.

我尝试了这种方法并且有效:

@description('Configuration Store Name')
param configurationStoreName string

@description('key prefix')
param prefix string

@description('key name')
param keyName string

@description('value')
param value string

@description('label')
param label string

@description('content type')
param contentType string = 'string'

@description('Deployment Environment')
param deploymentEnvironment string = 'dev'

resource configurationStore 'Microsoft.AppConfiguration/configurationStores@2021-10-01-preview' existing = {
name: configurationStoreName
}

var keyValueName = empty(label) ? '${prefix}:${keyName}' : '${prefix}:${keyName}$${label}'

resource configurationStoreValue 'Microsoft.AppConfiguration/configurationStores/keyValues@2021-10-01-preview' = {
name: keyValueName
parent: configurationStore
properties: {
contentType: contentType
value: value
tags: {
environment: deploymentEnvironment
}
}
}

关于Azure 应用程序配置存储 - 使用 Bicep 设置键值标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71458903/

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