I want to auto scale up / down the Azure virtual machine scale set by updating the instance value using C#. Please suggest how it can be done using C#.
using Microsoft.Azure.Management.Fluent; using Microsoft.Azure.Management.ResourceManager.Fluent; using System; namespace vmssScale { class Program { static void Main(string[] args) { var AppId = "2822a0d2-04f4-4337-aa0b-481963d5f37f"; var AppSecret = "K3b7rzZQ9-fOCj.Pv~ctRm5_ZgVkoK.355"; var tenant = "afebbe05-f314-492a-9035-3b68dee7fea1"; var subscriptionID = "f1b96a0f-2775-420f-b692-3f13bcdf0060"; var vmScaleSetGroup = "devtest-RG"; var vmScaleSetName = "devVMSS"; var credentials = SdkContext.AzureCredentialsFactory.FromServicePrincipal(AppId, AppSecret, tenant, AzureEnvironment.AzureGlobalCloud); var azure = Azure.Configure().Authenticate(credentials).WithSubscription(subscriptionID); var vmScaleSetID = "/subscriptions/" + subscriptionID + "/resourceGroups/" + vmScaleSetGroup + "/providers/Microsoft.Compute/virtualMachines/" + vmScaleSetName; var vmScaleSet = azure.VirtualMachineScaleSets.GetById(vmScaleSetID); //set as 5 instance var instanceValue = 3; Console.WriteLine("start to change instance value,it will take several mins..."); vmScaleSet.Update().WithCapacity(instanceValue).Apply(); Console.WriteLine("Done"); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)