Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Resource Group with Azure Management C# API

Tags:

c#

azure

Is there a way to create a Resource Group with the Azure Management C# API?

Basically this REST API call: https://msdn.microsoft.com/en-us/library/azure/dn790525.aspx

I found a way to create an Affinity Group by using client.AffinityGroups.Create, but that's the closest thing I've found.

like image 749
user3115696 Avatar asked Jul 02 '15 16:07

user3115696


People also ask

What is the difference between management group and resource group in Azure?

Management Groups contain one or more subscriptions. Inside of Subscriptions are Resource Groups. Resource Groups belong to exactly one Subscription. A Subscription can have many resource groups, but a resource group may belong to only one subscription.


2 Answers

I found the API call was hidden in a library which is only in preview mode at the moment. It's found in the following NuGet package, enable include prerelease in Visual Studio to find it in the NuGet client.

https://www.nuget.org/packages/Microsoft.Azure.Management.Resources/

Then to create a resource group I can use

var credentials = new TokenCloudCredentials("", "");
var client = new Microsoft.Azure.Management.Resources.ResourceManagementClient(credentials);            
var result = c.ResourceGroups.CreateOrUpdateAsync("MyResourceGroup", new Microsoft.Azure.Management.Resources.Models.ResourceGroup("West US"), new System.Threading.CancellationToken()).Result;

There is another stack overflow post explaining how to do the authentication: How to get Tags of Azure ResourceManagementClient object

The following blog post explains how to set up TokenCloudCredentials, required for the authentication part, in more detail, but only for command line apps: http://www.bradygaster.com/post/using-windows-azure-active-directory-to-authenticate-the-management-libraries

If you want to use something other than a command line app the following can work for authentication: http://www.dushyantgill.com/blog/2015/05/23/developers-guide-to-auth-with-azure-resource-manager-api/

like image 88
user3115696 Avatar answered Oct 02 '22 07:10

user3115696


Go to https://resources.azure.com - the ARMExplorer shows both the REST and the PowerShell commands to create a resource group. All the APIs are REST based. In C#, send a WebClient request.

like image 20
viperguynaz Avatar answered Oct 02 '22 08:10

viperguynaz