Azure / azure-resource-manager-schemas

Schemas used to author and validate Resource Manager Templates. These schemas power the intellisense and syntax completion in our ARM Tools VSCode extension, as well as the Export Template API
MIT License
611 stars 517 forks source link

subnet disordered in CreateUIDefinition vnetSpec #809

Open rainer37 opened 4 years ago

rainer37 commented 4 years ago

When i test my createuidefinition on the UI sandbox, i found that the default value for subnets defined in vnetSpec are not properly ordered.

For example, i have three subnets[1-3] default named as "WAN", "LAN", and "AIN" accordingly. Yet when i checked on the UI page and also the json output, i found that the order of these subnets are not mapping properly, resulting in "WAN->AIN", "LAN->LAN", and "AIN->WAN".

From my observations, the order of subnets shown on the UI page is ordered by the order they are defined in the template file, normally subnet1, subnet2 and then subnet3, (or maybe just lexicographical order). However, when populating the default values for these subnets, the orders becomes lexicographical order by subnet's name or some similar way of ordering. Hence WAN as subnet1 shown on the first subnet on the UI page, yet the default value popped for WAN is the first elements in lexi order which is AIN.

I am not sure if this problem only happens in Sandbox since my template is not being published yet, so maybe also check for the production UI generation page, could be the same problem. Any adjustment would be much appreciated, Thanks!

quinn-mchugh commented 4 years ago

Hello! Can you please add the schema you were using when you encountered this error? Thanks!

rainer37 commented 4 years ago

Sorry for delay, somehow missed the notifications. I can confirm this bug is also affect Azure's UI combos in production system, since i have customers reporting this issue. The problem happens after we adopt version "0.1.2-preview".

Below it a snippet i modified based on the example from https://docs.microsoft.com/en-us/azure/azure-resource-manager/managed-applications/microsoft-network-virtualnetworkcombo.

{ "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#", "handler": "Microsoft.Azure.CreateUIDef", "version": "0.1.2-preview", "parameters": { "basics": [ ], "steps": [ { "name": "instanceDetails", "label": "Instance Details", "subLabel": { "preValidation": "Configure Instance Details", "postValidation": "Done" }, "bladeTitle": "Instance Details", "elements": [ { "name": "element1", "type": "Microsoft.Network.VirtualNetworkCombo", "label": { "virtualNetwork": "Virtual network", "subnets": "Subnets" }, "toolTip": { "virtualNetwork": "", "subnets": "" }, "defaultValue": { "name": "vnet01", "addressPrefixSize": "/16" }, "constraints": { "minAddressPrefixSize": "/16" }, "options": { "hideExisting": false }, "subnets": { "subnet1": { "label": "First subnet", "defaultValue": { "name": "subnet-wan", "addressPrefixSize": "/24" }, "constraints": { "minAddressPrefixSize": "/24", "minAddressCount": 12, "requireContiguousAddresses": true } }, "subnet2": { "label": "Second subnet", "defaultValue": { "name": "subnet-lan", "addressPrefixSize": "/24" }, "constraints": { "minAddressPrefixSize": "/24", "minAddressCount": 8, "requireContiguousAddresses": true } } }, "visible": true } ] } ], "outputs": { } } }

  1. In this example, I give the default name "subnet-wan" for "First Subnet", and "subnet-lan" for "Second Subnet", and i also change the "addressPrefixSize" to /24 on subnet2. If you paste into the UI sandbox, and on the vnet create page you would be seeing the default names are not properly ordered, and if you keep clicking next, the output on final step would also give you the undesired values for subnet names.

  2. The problem maybe more obvious if you use three subnets, then you would find they are not simply "flipped", but the ordered alphabetically.

  3. Also i found the occurrence of bug somehow is related to the "addressPrefixSize" also. If you could change the prefix for subnet2 to other value, like /26, you will spot another buggy behavior, where one of the subnet doesn't get default name at all.

Hope these info helps, thanks!