MissingJsonReferenceId for passing in objects/arrays #2097
-
Using this as a guide: https://docs.microsoft.com/en-us/azure/templates/microsoft.network/virtualnetworks?tabs=json I'm trying to dynamically build out a vnet with stuff; just toying around with the abilities of Bicep/ARM (Cos dynamic = 👍) Here is my code example: param p_vnetObject object = {
name : 'asdf1'
cidr : [
'10.0.0.0/22'
]
subnets : [
{
name : 'subnet1'
addressPrefix : '10.0.0.0/24'
netWatcherName: 'myNetWacherLogs1'
nsgName : 'subnet1'
routeTable : 'subnet1'
}
{
name : 'subnet2'
addressPrefix : '10.0.1.0/24'
netWatcherName: 'myNetWacherLogs2'
nsgName : 'subnet2'
routeTable : 'subnet2'
}
]
}
param p_nsgObject object = {
subnet1: {
rules: [
{
name : 'rule1'
properties : {
access : 'Allow'
destinationAddressPrefix: '*'
destinationPortRange : '*'
direction : 'Inbound'
priority : 100
protocol : '*'
sourceAddressPrefix : '*'
sourcePortRange : '*'
}
}
{
name : 'rule2'
properties : {
access : 'Allow'
destinationAddressPrefix: '*'
destinationPortRange : '*'
direction : 'Outbound'
priority : 110
protocol : '*'
sourceAddressPrefix : '*'
sourcePortRange : '*'
}
}
]
}
subnet2: {
rules: [
{
name : 'rule1'
properties : {
access : 'Allow'
destinationAddressPrefix: '*'
destinationPortRange : '*'
direction : 'Inbound'
priority : 100
protocol : '*'
sourceAddressPrefix : '*'
sourcePortRange : '*'
}
}
]
}
}
param p_routeTables object = {
subnet1: {
routes : [
{
name : 'route11'
properties : {
addressPrefix : '0.0.0.0/0'
nextHopType : 'VirtualAppliance'
nextHopIpAddress: '1.1.1.1'
}
}
{
name : 'route12'
properties : {
addressPrefix : '10.0.0.0/24'
nextHopType : 'VirtualAppliance'
nextHopIpAddress: '1.1.1.1'
}
}
]
}
subnet2: {
routes : [
{
name : 'route21'
properties : {
addressPrefix : '0.0.0.0/0'
nextHopType : 'VirtualAppliance'
nextHopIpAddress: '1.1.1.1'
}
}
{
name : 'route22'
properties : {
addressPrefix : '10.0.0.0/24'
nextHopType : 'VirtualAppliance'
nextHopIpAddress: '1.1.1.1'
}
}
]
}
}
resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name : p_vnetObject.name
location : resourceGroup().location
properties : {
addressSpace : {
addressPrefixes : p_vnetObject.cidr
}
subnets : [for subitem in p_vnetObject.subnets: {
name : subitem.name
properties : {
addressPrefix : subitem.addressPrefix
networkSecurityGroup: {
properties: {
securityRules: [
p_nsgObject[subitem.nsgName].rules
]
}
}
routeTable: {
properties: {
routes: p_routeTables[subitem.routeTable].routes
}
}
}
}]
}
}
output o_vnetObject object = vnet
As you can see, i'm just chucking an array of stuff nested inside an object. Seems straight forward enough. But i get the following error: {
"error": {
"code": "InvalidRequestFormat",
"message": "Cannot parse the request.",
"details": [
{
"code": "MissingJsonReferenceId",
"message": "Value for reference id is missing. Path properties.subnets[0].properties.networkSecurityGroup."
},
{
"code": "MissingJsonReferenceId",
"message": "Value for reference id is missing. Path properties.subnets[0].properties.routeTable."
},
{
"code": "MissingJsonReferenceId",
"message": "Value for reference id is missing. Path properties.subnets[1].properties.networkSecurityGroup."
},
{
"code": "MissingJsonReferenceId",
"message": "Value for reference id is missing. Path properties.subnets[1].properties.routeTable."
}
]
}
} So i figure i've screwed somthing up, and thought i'd just whack it all in there and see if that works: resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name : p_vnetObject.name
location : resourceGroup().location
properties : {
addressSpace : {
addressPrefixes : p_vnetObject.cidr
}
subnets : [for subitem in p_vnetObject.subnets: {
name : subitem.name
properties : {
addressPrefix : subitem.addressPrefix
networkSecurityGroup: {
properties: {
securityRules: [
// p_nsgObject[subitem.nsgName].rules
{
name : 'rule1'
properties : {
access : 'Allow'
destinationAddressPrefix: '*'
destinationPortRange : '*'
direction : 'Inbound'
priority : 100
protocol : '*'
sourceAddressPrefix : '*'
sourcePortRange : '*'
}
}
{
name : 'rule2'
properties : {
access : 'Allow'
destinationAddressPrefix: '*'
destinationPortRange : '*'
direction : 'Outbound'
priority : 110
protocol : '*'
sourceAddressPrefix : '*'
sourcePortRange : '*'
}
}
]
}
}
// routeTable: {
// properties: {
// routes: p_routeTables[subitem.routeTable].routes
// }
// }
}
}]
}
} But this, too, errors. i have NFI why, and web search isn't bring up anything substansible. Can anyone please tell me what i'm doing wrong, or is it a limitation of Bicep/ARM? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Right, it's my own misunderstanding of how they get populated. One of those things when you post it, you get it a few min later. I think it's better to create separate resources and reference them via resource vnet 'Microsoft.Network/virtualNetworks@2020-06-01' = {
name : p_vnetObject.name
location : resourceGroup().location
properties : {
addressSpace : {
addressPrefixes : p_vnetObject.cidr
}
subnets : [for subitem in p_vnetObject.subnets: {
name : subitem.name
properties : {
addressPrefix : subitem.addressPrefix
networkSecurityGroup: {
id: '/subscriptions/asdfasdfasdf/resourceGroups/asdf/providers/Microsoft.Network/networkSecurityGroups/asdf1'
properties: {
securityRules: p_nsgObject[subitem.nsgName].rules
}
}
}
}]
}
} |
Beta Was this translation helpful? Give feedback.
Right, it's my own misunderstanding of how they get populated. One of those things when you post it, you get it a few min later. I think it's better to create separate resources and reference them via
resourceId()
, but for those who want to know what it looks like the way i was doing it: