你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

Bicep 错误/警告代码 - BCP035

当资源定义缺少所需属性时,会发生此错误/警告。

错误/警告说明

The specified <date-type> declaration is missing the following required properties: <property-name>.

解决方案

将缺少的属性添加到资源定义。

示例

以下示例引发了 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 = 'eastus'
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 的错误,因为缺少所需的属性值

@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 核心诊断