Azure App Configuration Store - 使用 Bicep 在键值上设置标签
Azure App Configuration Store - Setting label on keyvalues using Bicep
我正在尝试使用 Bicep 向 Azure 应用程序配置存储添加值。我在向键值添加标签时遇到问题。
这是我的模块:
@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 门户创建键值时完成,因此应该可以使用 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:
- Apply URL encoding
- Replace
~
with ~7E
- 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
}
}
}
我正在尝试使用 Bicep 向 Azure 应用程序配置存储添加值。我在向键值添加标签时遇到问题。
这是我的模块:
@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 门户创建键值时完成,因此应该可以使用 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, thekeyValues
resource with namemyKey
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:
- Apply URL encoding
- Replace
~
with~7E
- Replace
%
with~
For example, to create a key-value pair with key name
AppName:DbEndpoint
and label nameTest
, the resource name should beAppName~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
}
}
}