How to list my available subnets using ARM template

Joseph, Deon [JJCUS NON-J&J] 0 Reputation points
2024-06-07T05:38:52.6333333+00:00

Hi ,

I am using ARM templates from azure custom deployment page to create a storage account with private endpoint and azure vm. I need an option to enter the subnet to use. Currently it is a string parameter which needs to be entered manually checking available subnets with free ips.

User's image

I am looking for the option to add get the available subnets listed down here like in actual deployment from portal.

User's image

Is there a way to add this feature in ARM template?

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
7,472 questions
Azure Storage Accounts
Azure Storage Accounts
Globally unique resources that provide access to data management services and serve as the parent namespace for the services.
2,871 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 34,931 Reputation points Microsoft Employee
    2024-06-07T18:50:14.24+00:00

    @Joseph, Deon [JJCUS NON-J&J]

    You should be able to utilize Microsoft.Solutions.ResourceSelector UI element to accomplish this. The ResourceSelector user-interface (UI) element lets users select an existing Azure resource from a subscription. You specify the resource provider namespace and resource type, like Microsoft.Storage/storageAccounts in the element's JSON. You can use the element to filter the list by subscription or location. From the element's UI, to search within the list's contents, you can type a filter like resource group name, resource name, or a partial name.

    The sample on this page has references for how to do this with vnet and subnet. Relevant code pasted from uiFormDefinition.json

    {
    					"name": "networkSettings",
    					"label": "Network Settings",
    					"elements": [
    						{
    							"name": "vnetSelector",
    							"type": "Microsoft.Solutions.ResourceSelector",
    							"label": "Virtual Network",
    							"resourceType": "Microsoft.Network/virtualNetworks",
    							"options": {
    								"filter": {
    									"subscription": "onBasics",
    									"location": "onBasics"
    								}
    							}
    						},
    						{
    							"name": "subnets",
    							"type": "Microsoft.Solutions.ArmApiControl",
    							"request": {
    								"method": "GET",
    								"path": "[concat(steps('basics').resourceScope.subscription.id, '/resourceGroups/', last(take(split(steps('networkSettings').vnetSelector.id, '/'), 5)), '/providers/Microsoft.Network/virtualNetworks/', steps('networkSettings').vnetSelector.name,'/subnets?api-version=2022-01-01')]"
    							}
    						},
    						{
    							"name": "subnetList",
    							"type": "Microsoft.Common.DropDown",
    							"label": "Subnet",
    							"filter": true,
    							"constraints": {
    								"allowedValues": "[map(steps('networkSettings').subnets.value, (item) => parse(concat('{\"label\":\"', item.name, '\",\"value\":\"', item.id, '\"}')))]",
    								"required": true
    							},
    							"visible": true
    						},
    

    Let me know if this helps. Feel free to share the template and I will be happy to test this and see if I can get the drop-down selection working.


    If you still have questions, please let us know in the "comments" and we would be happy to help you. Comment is the fastest way of notifying the experts.

    If the answer has been helpful, we appreciate hearing from you and would love to help others who may have the same question. Accepting answers helps increase visibility of this question for other members of the Microsoft Q&A community.

    Thank you for helping to improve Microsoft Q&A! User's image

    0 comments No comments