Home > Software design >  Get Azure resource SKU using the Azure SDK for .NET
Get Azure resource SKU using the Azure SDK for .NET

Time:12-11

I am trying to get the tiers for my azure resources to then display them on my custom dashboard. I have done some research around this and have found this but I'm not too sure how to use it:

https://docs.microsoft.com/en-us/dotnet/api/microsoft.azure.management.resourcemanager.models.sku?view=azure-dotnet

I'm not sure if this is right because it doesn't require a connection string. Any help with this is greatly appreciated

CodePudding user response:

I think you should the SKU like this : https://docs.microsoft.com/en-us/dotnet/azure/sdk/resource-management?view=azure-dotnet

Regards

CodePudding user response:

If you know the ressource group, you can retrieve all informations like below :

/ First we construct our armClient
var armClient = new ArmClient(new DefaultAzureCredential());

// Next we get a resource group object
// ResourceGroup is a [Resource] object from above
Subscription subscription = await armClient.GetDefaultSubscriptionAsync();
ResourceGroup resourceGroup = await subscription.GetResourceGroups().GetAsync("myRgName");

// Next we get the collection for the virtual machines
// vmCollection is a [Resource]Collection object from above
VirtualMachineCollection vmCollection = resourceGroup.GetVirtualMachines();

// Next we loop over all vms in the collection
// Each vm is a [Resource] object from above
await foreach(VirtualMachine vm in vmCollection.GetAllAsync())
{
   // We access the [Resource]Data properties from vm.Data
   if(!vm.Data.Tags.ContainsKey("owner"))
   {
       // We can also access all operations from vm since it is already scoped for us
       await vm.StartAddTag("owner", GetOwner()).WaitForCompletionAsync();
   }
}

You can retrieve all virtualmachines for exemple in a ressource group so you can use this kind of code to retrieve the datas you want like tiers(SKU)

  • Related