I have object with not equal number of properties (and would like to keep it like this), i.e. second object is missing property "routeTable"
"subnets": {
"value":[
{
"name": "GatewaySubnet",
"addressPrefix": "10.2.0.0/24",
"networkSecurityGroup":"NSG-AllowAll",
"routeTable":"UDR-Default"
},
{
"name":"UnTrusted",
"addressPrefix":"10.2.1.0/24",
"networkSecurityGroup":"NSG-AllowAll",
}]}
Now I don't know how to check if property exists when iterating over object. The below gives error because of missing property "id": "[resourceID('Microsoft.Network/routeTables', parameters('subnets')[copyIndex('subnets')].routeTable)]"
My conditions for nested "id" property do not seem to work i.e.
"networkSecurityGroup": {
"id": "[resourceID('Microsoft.Network/networkSecurityGroups', if(equals(parameters('subnets')[copyIndex('subnets')].networkSecurityGroup, ''), json('null'), parameters('subnets')[copyIndex('subnets')].networkSecurityGroup))]"
}
ok, this is the best I can come up with:
you can probably make it better with some nested loops. but this works as well.
PS. I had use different names for nsg\udr as I am creating those dynamically, in your scenario if those exists it will work with identical names (this wont).