Getting started - Managing Compute Resources using Azure .NET SDK
This code sample will show you how to create a Virtual Machine using Azure SDK for .NET.
Features
This project framework provides examples for the following services:
Compute
- You can find the details for the library here.
Getting Started
Prerequisites
You will need the following values to authenticate to Azure
- Subscription ID
- Client ID
- Client Secret
- Tenant ID
These values can be obtained from the portal, here's the instructions:
Get Subscription ID
- Login into your Azure account
- Select Subscriptions in the left sidebar
- Select whichever subscription is needed
- Click on Overview
- Copy the Subscription ID
Get Client ID / Client Secret / Tenant ID
For information on how to get Client ID, Client Secret, and Tenant ID, please refer to this document
Setting Environment Variables
After you obtained the values, you need to set the following values as your environment variables
AZURE_CLIENT_ID
AZURE_CLIENT_SECRET
AZURE_TENANT_ID
AZURE_SUBSCRIPTION_ID
To set the following environment variables on your development system:
Windows (Note: Administrator access is required)
- Open the Control Panel
- Click System Security, then System
- Click Advanced system settings on the left
- Inside the System Properties window, click the Environment Variables… button.
- Click on the property you would like to change, then click the Edit… button. If the property name is not listed, then click the New… button.
Linux-based OS :
export AZURE_CLIENT_ID="__CLIENT_ID__"
export AZURE_CLIENT_SECRET="__CLIENT_SECRET__"
export AZURE_TENANT_ID="__TENANT_ID__"
export AZURE_SUBSCRIPTION_ID="__SUBSCRIPTION_ID__"
Installation
To complete this tutorial:
If you don't have an Azure subscription, create a free account before you begin.
Quickstart
- Clone the repository on your machine:
git clone https://github.com/Azure-Samples/azure-samples-net-management.git
- Switch to the project folder:
cd samples/compute/create-virtual-machine
- Replace the
AdminUsername
andAdminPassowrd
in the following code snip from Program.cs file.
protected static string AdminUsername = "<username>";
protected static string AdminPassword = "<password>";
- Run the application with the
dotnet run
command.
dotnet run
This sample shows how to do following operations to create a Virtual Machine
- Create a Resource Group.
- Create a AvailabilitySet.
- Create a IP Address.
- Create a Virtual Network.
- Craete a Network Interface.
- Create a Virtual Machine.
More information
The Azure Compute documentation includes a rich set of tutorials and conceptual articles, which serve as a good complement to the samples.
This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.