简体   繁体   中英

Create Resource Group with Azure Management C# API

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.

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/

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM