Reputation: 363
I am trying to find the resource group allocated to a VM in azure using nodejs.
I am using the below link as my reference https://learn.microsoft.com/en-us/samples/azure-samples/resource-manager-node-resources-and-groups/resource-manager-node-resources-and-groups/#list-groups
The below gets resource group details If I provide resourceGroupName and subscription_Id
https://learn.microsoft.com/en-us/rest/api/resources/resource-groups/get
But I only have VM name and subsciption_Id
Any help appreciated. Thanks in advance
Upvotes: 0
Views: 593
Reputation: 3804
Take a look here: https://learn.microsoft.com/en-us/samples/azure-samples/compute-node-manage-vm/compute-node-manage-vm/
This shows an example where you can list all VMs in a subsription.
computeClient.virtualMachines.listAll(function (err, result)
The will result in the VM ID which will have the RG name in it (TESTRG9397 in this example).
id: '/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/TESTRG9397/providers/Microsoft.Compute/virtualMachines/testvm3365'
You will have to parse the ID to get it but then you will have RG and SUB so you can call
computeClient.virtualMachines.get(resourceGroupName, vmName, function (err, result))
Upvotes: 2