我希望为我的vNet对等方实施一种数据驱动的方法,这样我就可以通过添加到参数文件来添加其他对等方
这是我的二头肌
param peers object
resource sourcevNet 'Microsoft.Network/virtualNetworks@2021-03-01' existing = {
name: peers.vNetPeeringSourceNetwork
}
resource vNetPeer 'Microsoft.Network/virtualNetworks/virtualNetworkPeerings@2020-05-01' = [ for j in range(0, length(peers.peerings)): {
parent: sourcevNet
name: '${peers.vNetPeeringSourceNetwork}-${peers.peerings[j]}'
properties: [ for i in range(0, length(peers.peerings[j].vNetPeeringDestinationNetwork)): {
allowVirtualNetworkAccess: peers.peerings[j].vNetPeeringDestinationNetwork[i].allowVirtualNetworkAccess
allowForwardedTraffic: peers.peerings[j].vNetPeeringDestinationNetwork[i].allowForwardedTraffic
allowGatewayTransit: peers.peerings[j].vNetPeeringDestinationNetwork[i].allowGatewayTransit
useRemoteGateways: peers.peerings[j].vNetPeeringDestinationNetwork[i].useRemoteGateways
remoteVirtualNetwork: {
id: peers.peerings[j].vNetPeeringDestinationNetwork[i].remote == false ? resourceId('${peers.peerings[j].vNetPeeringDestinationNetwork[i].peeredNetworkResourceGroup}','Microsoft.Network/virtualNetworks/', '${peers.peerings[j].vNetPeeringDestinationNetwork[i].peerNetworkSuffix}') : resourceId('${peers.peerings[j].vNetPeeringDestinationNetwork[i].remoteNetworkSubscription}','${peers.peerings[j].vNetPeeringDestinationNetwork[i].peeredNetworkResourceGroup}','Microsoft.Network/virtualNetworks/', '${peers.peerings[j].vNetPeeringDestinationNetwork[i].peerNetworkSuffix}')
}
}]
}]
这是参数
{
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentParameters.json#",
"contentVersion": "1.0.0.0",
"parameters":
{
"peers": {
"value":{
"peerings":[
{
"vNetPeeringSourceNetwork": "Test-VM2",
"vNetPeeringDestinationNetwork": [
{
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": true,
"allowGatewayTransit": false,
"useRemoteGateways": false,
"remote": false,
"peerNetworkSuffix": "TestVM-vnet",
"peeredNetworkResourceGroup": "TestVM",
"remoteNetworkSubscription": "37beac69-e9c7-40fc-9d7b-6c1adf274185"
},
{
"allowVirtualNetworkAccess": true,
"allowForwardedTraffic": true,
"allowGatewayTransit": false,
"useRemoteGateways": false,
"remote": false,
"peerNetworkSuffix": "TestVM-vnet3",
"peeredNetworkResourceGroup": "TestVM",
"remoteNetworkSubscription": "37beac69-e9c7-40fc-9d7b-6c1adf274185"
}
]
}
]
}
}
}
}
由于某种原因,它不喜欢属性的第二个循环。
属性“properties”需要类型为“VirtualNetworkPeeringPropertiesFormat”的值|null”,但提供的值类型为“object[]"。如果这是文档中的错误,请将其报告给Bicep Team.bicephttps://aka.ms/bicep-type-issues
任何帮助都将不胜感激!
1条答案
按热度按时间lf5gs5x21#
vNetPeer
资源上的properties
属性应该是一个对象,但您传递的是一个数组(由于循环)。尚不支持嵌套循环(请参阅github issue)。
在您的情况下,可以将资源的创建 Package 在模块中。
同样在ARM参数文件中,可以直接使用数组,这样就不必执行
peers.peerings
参数.json文件:
vnet-peering.二头肌模块:
和主.二头肌模板: