How to automate creation of App Service Plan in Azure using Azure SDK

Usually you may not be automating creation of App Service Plan in your azure infrastructure. Usually App Service Plan is something you create one time with required type of operating system and pricing tier. But if you are doing a true Infrastructure As Code deployment, then following code will help you in creating an App Service Plan using C# with Azure Sdk.

static void Main(string[] args)
            Console.WriteLine("Cloud Robot - Start");

            var prinicipalCredentials = SdkContext.AzureCredentialsFactory.FromFile("./");
            var azureInstance = Azure.Configure()
            var rgName = "my-rg";
            var rgLocation = "eastus";

            var rg = azureInstance.ResourceGroups.Define(rgName).WithRegion(rgLocation).Create();
            Console.WriteLine($"Resource group {rg.Name} created in region {rg.RegionName}");

            var appServicePlan = "my-webtest1-plan";
            var servicePlan = Task.Run(async () => await azureInstance.AppServices.AppServicePlans

            Console.WriteLine($"App Service Plan {servicePlan.Name} created in {servicePlan.Region}");

            Console.WriteLine("Cloud Robot - End");

In your code, you will have an external configuration file that provides settings like resource group name, plan name etc. Just for demonstration purpose, I have hard coded the names in code itself.




3.9 °C / 39.0 °F

weather conditions Clear

Monthly Posts

Blog Tags