Archive for July, 2021

createUiDefinition.json: Selecting existing resources

I was asked how to use two controls from Create UI definition elements – Azure Managed Applications | Microsoft Docs:

The first control displays a list of resources of a given type and is quite handy. The other calls an Azure REST API and delivers the results. There is no default way to display the results; you need to couple the ArmApiControl with a display if you want to show any values. I wrote the following little createUiDefinition.json file to demonstrate how to use these against something many actively used Azure Subscriptions contains: storage accounts.

All the information is on a blade called bladeData. The first item uses the “easy” path. The second uses the ArmApiControl paired with a dropdown. Both display the list of storage accounts in the customer subscription.

{
    "$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": "bladeData",
                "label": "My blade",
                "elements": [
                  {
                    "name": "resourceSelector",
                    "type": "Microsoft.Solutions.ResourceSelector",
                    "label": "Available storage accounts (Resource Selector)",
                    "resourceType": "Microsoft.Storage/storageAccounts",
                    "toolTip": "Select a storage account from the available list.",
                    "options": {
                      "filter": {
                        "subscription": "onBasics",
                        "location": "onBasics"
                      }
                    },
                    "visible": true
                  },
                  {
                    "name": "armApiControl",
                    "type": "Microsoft.Solutions.ArmApiControl",
                    "request": {
                      "method": "GET",
                      "path": "[concat(subscription().id, '/providers/Microsoft.Storage/storageAccounts?api-version=2021-04-01')]"
                    }
                  },
                  {
                    "name": "providerDropDown",
                    "type": "Microsoft.Common.DropDown",
                    "label": "Available storage accounts (Arm API)",
                    "toolTip": "Select a storage account from the available list.",
                    "constraints": {
                      "allowedValues": "[map(steps('bladeData').armApiControl.value, (item) => parse(concat('{\"label\":\"', item.name, '\",\"value\":\"', item.name, '\"}')))]"
                    },
                    "visible": true
                  }
                ]
            }
        ],
        "outputs": {
            "resourceGroup": "[resourceGroup().name]",
            "location": "[resourceGroup().location]"

        }
    }
}

Leave a comment