Bicep 诊断代码 – BCP035
当资源定义缺少所需属性时,会发生此诊断。
说明
指定的 <date-type> 声明缺少以下必需属性:<property-name>。
Level
警告/错误
解决方案
将缺少的属性添加到资源定义。
示例
以下示例会引发 virtualNetworkGateway1 和 virtualNetworkGateway2 诊断:
var networkConnectionName = 'testConnection'
var location = 'eastus'
var vnetGwAId = 'gatewayA'
var vnetGwBId = 'gatewayB'
resource networkConnection 'Microsoft.Network/connections@2023-11-01' = {
name: networkConnectionName
location: location
properties: {
virtualNetworkGateway1: {
id: vnetGwAId
}
virtualNetworkGateway2: {
id: vnetGwBId
}
connectionType: 'Vnet2Vnet'
}
}
此诊断为:
The specified "object" declaration is missing the following required properties: "properties". If this is an inaccuracy in the documentation, please report it to the Bicep Team.
可以通过模板参考验证缺少的属性。 如果你看到 Visual Studio Code 中的警告,请将光标悬停在资源符号名称上,然后选择“查看文档”以打开模板参考。
可以通过添加缺少的属性来解决此问题:
var networkConnectionName = 'testConnection'
var location = 'chinanorth3'
var vnetGwAId = 'gatewayA'
var vnetGwBId = 'gatewayB'
resource networkConnection 'Microsoft.Network/connections@2023-11-01' = {
name: networkConnectionName
location: location
properties: {
virtualNetworkGateway1: {
id: vnetGwAId
properties:{}
}
virtualNetworkGateway2: {
id: vnetGwBId
properties:{}
}
connectionType: 'Vnet2Vnet'
}
}
以下示例会引发 outValue 诊断,因为缺少所需的属性 value:
@discriminator('type')
type taggedUnion = {type: 'foo', value: int} | {type: 'bar', value: bool}
output outValue taggedUnion = {type: 'foo'}
可以通过添加缺少的属性来解决此问题:
@discriminator('type')
type taggedUnion = {type: 'foo', value: int} | {type: 'bar', value: bool}
output outValue taggedUnion = {type: 'foo', value: 3}
后续步骤
有关 Bicep 诊断的详细信息,请参阅 Bicep 核心诊断。